IAE Academy

GATE 2018 CS Q.24: solution and answer

GATE 2018 · CSQ.24 · 1 mark · NAT

Consider a system with 3 processes that share 4 instances of the same resource type. Each process can request a maximum of instances. Resource instances can be requested and released only one at a time. The largest value of that will always avoid deadlock is ____.

See the question in the paper

Answer and solution

ANSWER

The largest value of K that always avoids deadlock is 2.

Official answer: 2Source: Official answer key, GATE 2018 CS (IIT Guwahati)

  1. Deadlock needs every process to hold some instances while waiting for one more, with no free instance left.

  2. The worst case is that each of the 3 processes holds instances, one short of its maximum . The total held is then .

  3. Deadlock is impossible if at least one instance is still free in that worst case. So we need , which is .

  4. This gives , so .

  5. Check : each process holds at most 1 instance while it still needs another, so at most 3 are held. The 4th instance is free. Some process gets its second instance, finishes and releases. The others can then finish too, so there is no deadlock.

  6. Check : take the split 2, 1, 1 with 0 free. Each process needs one more instance to reach its maximum of 3, and none is available. Deadlock is possible, so does not always avoid deadlock.

  7. The largest that always avoids deadlock is .

KEY IDEA

With processes, instances and a maximum need of each, deadlock is impossible when . Here gives .

WATCH OUT FOR

Setting and getting , which wrongly requires every process to be able to finish at once. The right test is that the worst case, each process holding , still leaves one instance free.

From the GATE 2018 CS paper. Every question of this paper · Download the full paper · All 6 Deadlock questions, with notes

More Deadlock questions