A system has n resources R0,...,Rn-1, and k processes P0,....Pk-1. The…

2010

A system has n resources R0,...,Rn-1, and k processes P0,....Pk-1. The implementation of the resource request logic of each process Pi . is as follows:

if (i % 2 == 0) {
if (i < n) request R<sub>i</sub>
if (i+2 < n) request R<sub>i+2</sub>
}
else {
if (i < n) request R<sub>n-i</sub>
if (i+2 < n) request R<sub>n-i-2</sub>
}

In which one of the following situations is a deadlock possible?

  1. A.

    n=40, k=26

  2. B.

    n=21, k=12

  3. C.

    n=20, k=10

  4. D.

    n=41, k=19

Attempted by 48 students.

Show answer & explanation

Correct answer: B

Short answer: Deadlock is possible for n=21, k=12 and not for the other listed cases.

Reason and general condition:

  • An even-indexed process e requests resources in order: R_e then R_{e+2} (when e < n and e+2 < n).

  • An odd-indexed process o requests resources in order: R_{n-o} then R_{n-o-2} (when o < n and n-o-2 >= 0).

  • For a two-process circular wait we need one process to request R_x then R_y while another requests R_y then R_x. Equating the resource names gives o = n - e - 2.

  • Because e is even, o has the same parity as n. For o to be odd (required since o is an odd-indexed process) n must be odd. Therefore n must be odd for such a pair to exist.

  • Also require both processes to exist: e < k and o = n - e - 2 < k. Combining these yields an integer even e satisfying: e >= n - k - 1 and e <= min(k - 1, n - 3). If such an even e exists, deadlock is possible.

Apply the condition to each case:

  • n=21, k=12: Compute bounds: e >= 21 - 12 - 1 = 8 and e <= min(11, 18) = 11. There are even e values in [8,11] (for example e = 10). Then o = 21 - 10 - 2 = 9, which is < k, so processes with indices 10 (even) and 9 (odd) form the circular wait: process 10 takes R10 then waits for R12, while process 9 takes R12 then waits for R10. Hence deadlock is possible.

  • n=40, k=26: n is even, so the parity requirement fails and no odd-index partner o can match the needed swapped request order. Deadlock cannot occur under this pattern.

  • n=20, k=10: n is even, so the swapped-order pairing is impossible and deadlock cannot occur.

  • n=41, k=19: n is odd, but compute bounds: e >= 41 - 19 - 1 = 21 and e <= min(18, 38) = 18. The lower bound exceeds the upper bound, so no valid e exists within the process range. Therefore no deadlock can form.

Conclusion: The only listed case where the required pair of processes exists is n=21, k=12, so that case permits deadlock.

Explore the full course: Gate Guidance By Sanchit Sir