CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ

Semaphores s = 2 and t = 0. T1 runs twice: wait(s); print('a'); signal(t). T2 runs twice: wait(t); print('b'); signal(s). Which outputs are possible?

  1. A. abab only
  2. B. aabb only
  3. C. abab and aabb
  4. D. abab, aabb and abba

Correct answer: C. abab and aabb

Since s starts at 2, T1 may print both a's before T2 runs (aabb), or T2 may print b in between (abab). A b always needs a preceding a (t starts at 0), so abba and any output starting with b are impossible.

More Operating Systems questions

Exams that ask this topic