如何判断这个系统是否会出现死锁?

发布于 2024-10-19 09:18:51 字数 71 浏览 3 评论 0原文

N个进程共享M个资源单元,每次只能保留和释放一个。每个进程的最大需求不超过M,并且所有最大需求之和小于M+N。系统会出现死锁吗?

N processes share M resource units that can be reserved and release only one at a time. The maximum need of each process does not exceed M, and the sum of all maximum needs is less than M+N. Can a deadlock occur in the system ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热血少△年 2024-10-26 09:18:51

我希望你得到答案。为其他访客回答这个问题。

答案是系统不会发生死锁

证明如下图所示。

该图像取自 http://alumni.cs.ucr .edu/~choua/school/cs153/Solution%20Manual.pdf 第 31 页

I hope you got the answer. Answering this question for other visitors.

The answer is that the deadlock will not occur in the system.

The proof is given in the image below.

The image was taken from http://alumni.cs.ucr.edu/~choua/school/cs153/Solution%20Manual.pdf on page 31

风向决定发型 2024-10-26 09:18:51

您所描述的系统看起来像信号量

关于您的最后一个问题:是的。你“可以”总是陷入僵局;如果您不明白如何做,请询问年轻/可耻/有上进心/异常的开发人员。

一种好方法,造就一个好方法;就是有奇怪的锁定/释放资源规则。例如,如果一个进程需要 M 个资源来执行任务,他可以立即锁定其中一半,然后等待另一半可用后再执行任何操作。

我认为他永远不会放弃,直到他拥有 M 种宝贵的资源,并在任务完成后将它们全部释放。

单个进程不会造成太大问题,但多个进程会造成太大问题,因为它们将锁定超过 M 个总资源,并且需要更多资源才能摆脱这种冻结状态。

the system you are describing looks like semaphores

about your last question : YES. You "could" always do a deadlock ; if you don't see how, ask a young/shameful/motivated/deviant developer.

One good way to make a good one ; is to have strange locking/releasing resources rules. For example, if a process needs M resources to perform a task, he could locks half of them right away, and then waits for the other half to be available before doing anything.

I assume he never gives up until he have its M precious resources and releases them all once the task done.

A single process wouldn't cause much problems but several will as they will lock more than M total resources and will need more of them to get out this frozen state.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文