GATE / CS ARCHIVE

GATE CSE 2013 / QUESTION 16

Deadlock-free semaphore acquisition

Operating Systems · Deadlocks · Full GATE CSE 2013 paper

GATE 2013, Q16 1 mark · MCQ
Report issue

Deadlocks

Question 16, GATE 2013: Binary semaphores a, b, c, d start at 1. X acquires a, b, c; Y acquires b, c, d; Z acquires c, d, a, then each releases its three locks after work. Which acquisition ordering is deadlock-free? A X:abc, Y:bcd, Z:cda; B X:bac, Y:bcd, Z:acd; C X:bac, Y:cbd, Z:acd; D X:abc, Y:cbd, Z:cda.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Option B respects a single global order b<a<c<d in every process: X takes b, a, c; Y takes b, c, d; Z takes a, c, d. A circular wait would require strictly increasing lock ranks around a cycle, which is impossible. The other choices admit contradictory acquisition orders and circular-wait executions. Thus B.

Assign ranks b=1, a=2, c=3, d=4. In B every process acquires strictly increasing ranks, so a process holding one lock can wait only for a higher-ranked lock. A circular chain would require rank to increase all the way back to its starting value, which is impossible. For contrast, A permits X holding a while Z holds c, d and waits for a, with X eventually waiting for c. C permits X holding b and Y holding c, each waiting for the other. D permits X holding a, b and Z holding c, d, with X waiting for c and Z for a. These are concrete circular waits, not merely inconvenient orderings.

Original paper, page 4 · Answer key