CS FundamentalsVery hardGATE CS (PYQ pattern)

Semaphores S = 0 and T = 0 are shared. P1 executes: print A; signal(S); print B. P2 executes: wait(S); print C; signal(T). P3 executes: print D; wait(T); print E. Each statement runs atomically and the processes run once concurrently. How many distinct output strings are possible?

  1. A. 11
  2. B. 9
  3. C. 12
  4. D. 10

Correct answer: A. 11

The constraints are A before B, A before C, C before E and D before E. Counting the valid interleavings of the five prints by exhaustively exploring schedules gives 11 distinct strings (for example ABCDE and DACEB, but not CDABE).

More Operating Systems questions

Exams that ask this topic