World's most popular travel blog for travel bloggers.

[Solved]: Confusion in Banker's Algorithm: How resources are allocated?

, , No Comments
Problem Detail: 

I have seen examples about Banker's Algorithm from this Wikipedia link, this book and many other places. In all these examples some processes are allocated resources less than their Max Need.

For example, consider the state of system as shown in below given image taken from Wikipedia link:

enter image description here

Here you can see that the process P1's Max Need is 3 3 2 2 and the total available resources are 6 5 7 6. But the system allocates 1 2 2 1 resources to P1. Although it could allocate all the requested resources to P1 and P1 would have completed.

So my questions are:

  • Why does the system allocate partial / incomplete resources even when it has the resources available
  • If the allocation of partial / incomplete resources is allowed, then why does the system / algorithm enforce that the number of requested / needed resources should be less than the available resources (at the time of request)?. The system could allocate some resources (available at the time of request) to process(es) and the remaining would have been assigned when released by other processes.

OR

The process has to tell the number of resource types (and their instances) in advance, but does not need to be assigned all resources at a time; rather it is assigned resources when actually needed?

Please correct me if I am wrong.

Asked By : swdeveloper

Answered By : vonbrand

The maximum resources are an estimate by the process of what they might need, the currently allocated is what the process holds at the moment. The idea is that processes request more resources as they need them (and at those points you run the algorithm to see if it could lead to deadlock to grant the resources asked for, by seeing if there is a process that could finish and release all it holds if it goes on to ask for it's maximum announced request, releases what it holds, and so on). If a process releases resources, that clearly can't lead to a deadlock, thus no special handling (except for recording what is free now) is needed.

Think of you e.g. building a box out of wood, and the tools needed. You'll need a saw, a drill, a screwdriver, among other tools. You'd announce that, but you won't require all together, while you are busy with the saw somebody else could use the drill and screwdriver, so it doesn't make sense to ask for all at the start, or keep all until finished.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/55432

3.2K people like this

 Download Related Notes/Documents

0 comments:

Post a Comment

Let us know your responses and feedback