银行家算法 [英] Bankers algorithm

查看:263
本文介绍了银行家算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于答案的Dijkstra的银行家算法(这个问题在下面的屏幕截图提供)一个问题的问题。

I have a question about the answer to a problem on Dijkstra's Banker's Algorithm (the question is provided in the screen shot below).

我认为这个问题的答案应该是是的,这是有可能做到这一点。我的想法是,一​​旦用户1完成后,我们就可以弹出他出去和自由他的要求resouces(10 A和5 B的),然后返回他所使用的资源,以现有的资源池,这将帮助别人做。

I thought the answer to this question should be "yes, it is possible to do it". My thinking is that once user 1 is done, we can pop him out and free his requested resouces (10 A's and 5 B's), and return his used resources to the available resources pool, which will assist the others to be done.

相反,答案(在屏幕截图的问题下面)指出这是不可能的。我哪里做错了?为什么是答案,这是不可能的?

Instead, the answer (in the screen shot beneath the question) states it's not possible. Where did I go wrong? Why is the answer that this is not possible?

答:

Answer:

推荐答案

我觉得这只是一个措辞不当的问题。这个问题说明指出,现有的资源 A = 10 B = 15

I think it's just a poorly worded question. The problem description states that the available resources are A = 10 and B = 15.

在银行家的算法,它被认为安全的,如果一个进程可以分配它所需要的最大资源。 (1过程需要10 A和5 B的)

In the Banker's algorithm it's considered "safe" if a process can allocate the maximum resources it needs. (process 1 needs 10 A's and 5 B's)

那么答案国可用资源 A = 1 B = 2 。如果你看一下所有当前分配号码的过程:

流程1了2个资源
流程2了3个资源
过程3了2个资源
流程4了2个资源
---------------------------
在使用总的A资源= 9

Then the answer states the available resources are A = 1 and B = 2. If you look at all the processes currently allocated numbers:

process 1 has 2 A resources
process 2 has 3 A resources
process 3 has 2 A resources
process 4 has 2 A resources
---------------------------
total A resources in use = 9

可以清楚地看到这个问题意味着这些是系统资源共,不是当前的可用资源。因此9的resouces都在使用,处理1,需要最多10(它有2个),所以它需要8个;在这种情况下,答案是否定的,它不是安全的。

it becomes clear that the question meant those were the Total System resources, not current available resources. Thus 9 A resouces are in use, process 1 requires a maximum of 10 (it has 2) so it needs 8 more; in which case the answer is no, it's not safe.

这篇关于银行家算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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