Skip to content
Official PYQ · 2010

GATE CS 2010 Q46 — Deadlock

Explain with AI

A system has nn resources R0,…,Rn−1R_0, \dots,R_{n-1}, and kk processes P0,…,Pk−1P_0, \dots, P_{k-1}. The implementation of the resource request logic of each process PiP_i is as follows:

if(i%2==0){\text{if} (i\%2==0) \{
if(i<n) request Ri;\quad\text{if} (i<n) \text{ request } R_i;
if(i+2<n) request Ri+2;}\quad\text{if} (i+2 < n) \text{ request } R_{i+2}; \}
else{\text{else} \{
if(i<n) request Rn−i;\quad\text{if} (i<n) \text{ request } R_{n-i};
if(i+2<n) request Rn−i−2;}\quad\text{if} (i+2 <n) \text{ request } R_{n-i-2}; \}

In which of the following situations is a deadlock possible?

Choose one option
View worked solution

Answer: B

To determine if a deadlock is possible, let us analyze the resource request patterns of the processes:

1. Even-indexed processes (PiP_i where ii is even):

  • Request RiR_i first, then Ri+2R_{i+2}.
  • They only request even-indexed resources in a strictly increasing order of indices (R0→R2→R4…R_0 \to R_2 \to R_4 \dots).

2. Odd-indexed processes (PiP_i where ii is odd):

  • Request Rn−iR_{n-i} first, then Rn−i−2R_{n-i-2}.
  • They request resources in a strictly decreasing order of indices.
  • If nn is even, n−in-i and n−i−2n-i-2 are odd. Thus, odd processes only request odd-indexed resources. Since even and odd processes access completely disjoint sets of resources, no interaction occurs, making deadlock impossible. This rules out options A and C.
  • If nn is odd, n−in-i and n−i−2n-i-2 are even. Thus, both even and odd processes compete for even-indexed resources. Since one group requests them in increasing order and the other in decreasing order, a deadlock cycle can form.

Let us test the remaining options with odd nn:

  • Option B (n=21,k=12n=21, k=12):
    Consider process P8P_8 (even) and P11P_{11} (odd):
    • P8P_8 requests R8R_8 then R10R_{10}.
    • P11P_{11} requests R21−11=R10R_{21-11} = R_{10} then R21−11−2=R8R_{21-11-2} = R_8.
    If P8P_8 acquires R8R_8 and P11P_{11} acquires R10R_{10}, they will wait for each other indefinitely, resulting in a deadlock.
  • Option D (n=41,k=19n=41, k=19):
    The maximum index requested by any even process is 1818 (requested by P16P_{16}). The minimum index requested by any odd process is 41−17−2=2241 - 17 - 2 = 22 (requested by P17P_{17}). Since the resource sets [0,18][0, 18] and [22,40][22, 40] are disjoint, no deadlock can occur.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Deadlock questions