CS FundamentalsHardGATE CS (PYQ pattern)

Six threads each take two locks in a fixed order and hold the first while acquiring the second: T1 takes A then B, T2: B then C, T3: C then A, T4: C then D, T5: D then B, T6: A then D. A deadlock is possible whenever the lock-order graph (edge X -> Y if some thread holds X while requesting Y) has a cycle. Exactly one thread may have its order reversed. Reversing which thread removes every possible deadlock?

  1. A. T3 only
  2. B. T1 only
  3. C. No single reversal suffices
  4. D. T2 only

Correct answer: D. T2 only

Edges A->B, B->C, C->A, C->D, D->B, A->D contain three cycles: A-B-C, B-C-D and A-D-B-C. Every cycle uses B->C, and reversing T2 gives the order C -> A -> D -> B consistent with all edges, so the graph becomes acyclic. Reversing T3 (C->A) leaves B-C-D; reversing T1 (A->B) leaves B-C-D and A-D-B-C.

More Operating Systems questions

Exams that ask this topic