CS FundamentalsHardAmazon · Microsoft MCQ pattern

Semaphores S = 1 and T = 0. Process X runs: wait(S); print('A'); signal(T); Process Y runs: wait(T); print('B'); signal(S); Each runs its code in an infinite loop. Which output prefix is possible?

  1. A. ABBA…
  2. B. AABB…
  3. C. ABAB…
  4. D. BABA…

Correct answer: C. ABAB…

Y cannot print until X signals T, and X cannot print again until Y signals S, so prints strictly alternate starting with A: ABAB… Any other pattern needs two consecutive prints by the same process, which the semaphores forbid.

More Operating Systems questions

Exams that ask this topic