GATE / CS ARCHIVE

GATE CSE 2010 / QUESTION 46

Deadlock from opposite resource orders

Operating Systems · Deadlocks · Full GATE CSE 2010 paper

GATE 2010, Q46 2 marks · MCQ
Report issue

Deadlocks

Question 46, GATE 2010: There are n single-instance resources R₀,…,Rₙ₋₁ and k processes P₀,…,Pₖ₋₁. Each process Pᵢ requests resources using:
if(i%2==0) {
 if(i<n) request Rᵢ;
 if(i+2<n) request Rᵢ₊₂;
} else {
 if(i<n) request Rₙ₋ᵢ;
 if(i−2<n) request Rₙ₋ᵢ₋₂;
}
For which offered n,k is deadlock possible? The odd-branch subscripts are faint in the scan; the explicit reading above preserves the inherited interpretation. The second odd-branch guard is printed i−2<n, not silently repaired.
Options: (A) n=40,k=26; (B) n=21,k=12; (C) n=20,k=10; (D) n=41,k=19.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Read the code as even i requesting Ri followed by R(i+2), and odd i requesting R(n−i) followed by R(n−i−2), subject to the printed guards. For n=21,k=12, P10 requests R10 then R12, while P9 requests R12 then R10. If each obtains its first resource, they wait on each other: deadlock is possible, B. For even n (A and C), even processes use only even-indexed resources in increasing order, while odd processes use only odd-indexed resources in decreasing order. Each parity class has a consistent order, so neither can cycle. For D, n=41,k=19: even processes use resources 0 through 20, whereas odd processes use even resources 22 through 40, so these opposite-order sets do not overlap and cannot form a cycle. This uses single-instance, non-preemptive resources held until completion, the standard deadlock model. The low-quality scan has faint minus signs/subscripts in the odd branch; the relevant R(n−i),R(n−i−2) reading is recorded explicitly.

The deadlocking B execution can be written explicitly: P10 acquires R10; P9 acquires R12; P10 blocks requesting R12; P9 blocks requesting R10. The resource-allocation graph now has a cycle with single-instance resources. Consistent increasing or decreasing order prevents cycles within one resource set, but opposing orders on overlapping resources can create the exhibited cycle.

Original paper, page 11