CS FundamentalsHardGATE CS (PYQ pattern)

Semaphores x = 0, y = 0. P1: print a; signal(x); wait(y); print b. P2: wait(x); print c; signal(y); print d. P3: print e. All three start together and the prints are atomic. How many different complete output strings can be produced?

  1. A. 14
  2. B. 4
  3. C. 22
  4. D. 10

Correct answer: D. 10

The constraints are a before c before b (via x then y), c before d, and e is free. Counting the interleavings of the orders a<c<{b,d} (b and d unordered) with e inserted anywhere gives 10 strings; there is no deadlock.

More Operating Systems questions

Exams that ask this topic