Similar questions 7 more →
Deadlocks

Answer & solution
Official answer: 6
Givens and goal
Five processes share k identical resource instances. Each process needs at most two, requests or releases only one at a time, and can request its second only after receiving its first. Find the smallest k guaranteeing freedom from resource deadlock.
Approach
Show an unsafe allocation for too few resources and prove that one additional resource always lets some process finish.
Step-by-step solution
1. With k=5, allocate one instance to each process. If all five then request a second, all five available instances are held and every process is waiting. No process can reach its maximum claim and finish: this is a possible deadlock.
2. Smaller positive capacities also fail to give a universal guarantee: the available instances can each be held by a different process waiting for its second, while the others wait for their first. Thus merely showing failure at five is consistent with the lower-capacity cases.
3. Now let k=6. If some process holds two instances, it has its complete maximum resource requirement and can finish without waiting for another instance, then release what it holds.
4. Otherwise each of the at most five processes holds at most one instance, so at most five are allocated. At least one of the six remains free. It can be granted as a second instance to a waiting holder, enabling that process to finish and release two.
5. Repeating the reasoning gives a safe sequence of completions, so a resource deadlock cannot arise. The smallest required capacity is 6.
This is the standard resource-deadlock model, assuming a process eventually completes when its maximum resource need is satisfied. It does not guarantee fair scheduling or rule out starvation caused by a scheduler.