CS FundamentalsVery hardGATE CS

Semaphores a = b = c = 0. P1: print A; signal(a); wait(b); wait(c); print X. P2: print B; signal(b); signal(b); wait(a); print Y. P3: print C; signal(c); wait(b); print Z. Which of these outputs is possible: ABCXYZ, BAYCZX, CBZAXY, ABXCYZ?

  1. A. All four
  2. B. ABCXYZ, BAYCZX, CBZAXY only
  3. C. ABCXYZ only
  4. D. ABCXYZ, BAYCZX and ABXCYZ only

Correct answer: B. ABCXYZ, BAYCZX, CBZAXY only

X needs b (after B) and c (after C); Y needs a (after A); Z needs b (after B). ABXCYZ prints X before C, which is impossible. The others respect every dependency, as an exhaustive interleaving check confirms.

More Operating Systems questions

Exams that ask this topic