CS FundamentalsHardGATE CS

Semaphores x = 0 and y = 0. P1: print('A'); signal(x); wait(y); print('B'). P2: print('C'); signal(y); wait(x); print('D'). Which of the strings ACBD, CADB, ABCD, CDAB can be printed?

  1. A. All four
  2. B. ACBD, CADB and ABCD only
  3. C. Only ACBD
  4. D. ACBD and CADB only

Correct answer: D. ACBD and CADB only

This is a rendezvous: B needs C (y) and D needs A (x), so both A and C must precede both B and D. ACBD and CADB satisfy this; ABCD prints B before C and CDAB prints D before A. All possible outputs: ACBD, ACDB, CABD, CADB.

More Operating Systems questions

Exams that ask this topic