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?
- A. T3 only
- B. T1 only
- C. No single reversal suffices
- 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
- Four processes (arrival, burst) in ms: A (0, 7), B (1, 2), C (2, 1), D (2, 2). Scheduling is non-preemptive. Compare non-preemptive SJF…
- A 2-slot bounded buffer uses mutex = 1, empty = 2, full = 0. Two producers each insert 2 items with the (buggy) code wait(mutex)…
- SRTF (preemptive shortest remaining time first; ties go to the earlier arrival) is used for processes (arrival, burst) in ms: P1 (0, 9)…
- Preemptive priority scheduling (a smaller number means higher priority; equal priorities are served by earlier arrival, without time…
- A lottery scheduler holds a fresh draw every quantum. Process A has 100 tickets, B has 200 and C has 300 (every process always stays…
- Rate-monotonic scheduling (preemptive, deadline = period, all tasks released together at t = 0) is used for T1 (C = 1, period 4), T2 (C =…