Question

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

Official answer and solution
Official answer
2
From
Official GATE 2018 answer key

Solution

Apply the pigeonhole principle to find the maximum demand per process that guarantees deadlock freedom.

Let P=3P = 3 be the number of processes and R=4R = 4 be the total number of resource instances. Each process has maximum claim KK.

In the worst-case allocation just before deadlock, each process holds K−1K - 1 instances without completing. Deadlock is guaranteed to be avoided if the total resources RR strictly exceeds the sum of these worst-case allocations:

P(K−1)+1≤RP(K - 1) + 1 \le R
3(K−1)+1≤43(K - 1) + 1 \le 4
3(K−1)≤3  ⟹  K−1≤1  ⟹  K≤23(K - 1) \le 3 \implies K - 1 \le 1 \implies K \le 2

If K=2K = 2, the maximum total held by 3 processes without finishing is 3×1=33 \times 1 = 3. With 4 resources available, at least 1 resource remains free, allowing at least one process to acquire its maximum and terminate.
If K=3K = 3, each process can hold 1 resource (3 held) with 1 free; giving that free resource to any process leaves it with 2, still short of 3, leading to deadlock.

Thus, the largest value of KK that avoids deadlock is 2.

Final answer

2

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2018 Computer Science and Information Technology (CS)
Question
34 of 65, printed as CS Q.24
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.