CS FundamentalsHardGATE CS

Semaphores s = 2, t = 0. Process X runs `repeat 2 times { wait(s); print('A'); signal(t); }` and Y runs `repeat 2 times { wait(t); print('B'); signal(s); }` concurrently. Which outputs are possible?

  1. A. ABAB only
  2. B. AABB only
  3. C. AABB and ABAB
  4. D. ABAB, AABB and ABBA

Correct answer: C. AABB and ABAB

With s = 2, X can print both A's before Y runs, or Y can print B after the first A. B can never come first and can never outrun the A's (t counts A's printed). Possible: AABB, ABAB.

More Operating Systems questions

Exams that ask this topic