CS FundamentalsVery hardGATE CS · Advanced

A semaphore s is initialised to 0. Three threads run concurrently, and print(X) prints the single letter X atomically. Thread 1: print(A); V(s); print(B). Thread 2: P(s); print(C); print(D). Thread 3: print(E); print(F). How many different complete output strings are possible?

  1. A. 41
  2. B. 45
  3. C. 90
  4. D. 51

Correct answer: B. 45

The outputs are the interleavings of A-B, C-D, E-F in which A comes before C (P(s) cannot pass before V(s), and A precedes V). Of the 90 interleavings of three 2-letter chains, those with A before C are counted: 45.

More Operating Systems questions

Exams that ask this topic