使用银行家算法避免死锁时如何找到安全序列?
在使用银行家算法避免死锁时,如何找到安全序列?如果我使用安全算法,它不会给出序列作为输出。那么我怎样才能得到一个安全的序列呢?
How can I find a safe sequence while using the Banker's algorithm for avoiding deadlock? If I use safety algorithm, it doesn't give a sequence as output. Then how would I get a sequence that is safe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过银行家算法,您可以知道可用资源的总数以及每个进程可能请求的最大资源数。保守地说,您毕竟是一名银行家,您假设任何流程在完成之前都会请求其最大资源。
当请求资源时,您首先查看是否有足够的剩余资源,以便至少一个进程可以接收其最大值。如果没有足够的资源,那么您将无法批准该请求,因为您将进入不安全状态。
现在假设您确定可以获得最大值并完成的所有进程都已完成并释放了它们所占用的资源。这将允许更多进程获取其最大请求并完成,从而释放更多资源。
重复直到所有进程都完成(在这种情况下,请求可以分配),或者即使所有可以完成的进程都释放了其资源,某些进程也无法获取其最大值。
在实践中(以及手工处理的考试问题),通常只需通过几次流程列表即可确定您是否处于安全或不安全状态。
With the banker's algorithm you know the total number of resources available, and the maximum number of resources that each process may request. Being conservative, you're a banker after all, you assume that any process will request its maximum resources before finishing.
When resources are requested, you look first at whether there are enough resources left so that at least one process can receive its maximum. If there would not be enough resources left then you cannot grant the request as you would enter an unsafe state.
Now assume that all the processes that you determined could acquire their maximum and finish have done so and released the resources that they were holding onto. This will allow more processes to acquire their maximum request and finish, freeing more resources.
Repeat until either all the processes have finished (in which case the request is OK to allocate), or there are some processes that cannot acquire their maximum even after all the processes that can finish have released their resources.
In practice (and on exam problems worked by hand) it usually does not take more than a couple of passes though the list of processes to see if you are in a safe or unsafe state.
在安全算法中,将完成的向量定义为初始化为零的整数数组。不要将完成的向量中的标志设置为 true,而是将其设置为递增的订单号。最后,完成的向量将包含序列顺序。未完成的流程的完成订单将为零。
In the safety algorithm, define the finished vector as an array of integers initialized to zero. Instead of setting the flag in the finished vector to true, set it to an incremented order number. At the end the finished vector will contain the sequence order. Unfinished processes will have their finished order equal to zero.