如何解释“死锁”更好? [英] How to explain the "deadlock" better?

查看:183
本文介绍了如何解释“死锁”更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在努力用简单的话解释死锁在线程,所以请帮助。什么可能是死锁(例如,在Java中)的最好的例子,以及它如何发生在步骤和如何防止它?但没有深入细节。我知道这就像问两个相反的事情,但仍然。如果你有任何以前的并行编程培训经验 - 这将是一流的!

I am struggling to explain "deadlock" in threads in easy words, so please help. What could be the best example of "deadlock" (say, in Java), and how it does happen in steps and how to prevent it? But without getting into details too deep. I know that's like asking two opposite things, but still. If you have any previous concurrent programming training experience -- it would be superb!

推荐答案

Jack和Jill恰好想三明治。两人都需要一片面包,所以他们都去拿面包和一把刀。

Jack and Jill happens to want to make a sandwich at the same time. Both need a slice of bread, so they both goes to get the loaf of bread and a knife.

杰克先吃刀,吉尔先吃面包。现在杰克试图找到面包和吉尔试图找到刀,但两个发现,他们需要完成任务已经在使用中。如果他们都决定等待,直到他们需要的不再使用,他们将永远等待彼此。死锁。

Jack gets the knife first, while Jill gets the loaf of bread first. Now Jack tries to find the loaf of bread and Jill tries to find the knife, but both find that what they need to finish the task is already in use. If they both decide to wait until what they need is no longer in use, they will wait for each other forever. Deadlock.

这篇关于如何解释“死锁”更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆