CS FundamentalsModerateGATE CS

Semaphores S = 1, T = 0, U = 0. X: wait(S); print('A'); signal(T). Y: wait(T); print('B'); signal(U). Z: wait(U); print('C'); signal(S). Each process runs its code once, concurrently. Which outputs are possible?

  1. A. ABC and ACB
  2. B. Only ABC
  3. C. Any permutation of A, B, C
  4. D. ABC, or deadlock if Z runs first

Correct answer: B. Only ABC

Only X can start (S = 1); B needs T from X and C needs U from Y, forcing A, B, C in that order. Z running first just blocks on U until Y signals, so there is no deadlock.

More Operating Systems questions

Exams that ask this topic