CS FundamentalsHardGATE CS

A semaphore S is initialised to 3. The operations wait(S) ×6, signal(S) ×2, wait(S) ×1 are issued in that order by different processes, and no process that blocks is ever woken except by these signals. Using the classical counting semaphore (value can go negative), what is the final value of S and how many processes are still blocked?

  1. A. 0 and 4
  2. B. −2 and 2
  3. C. −3 and 3
  4. D. 2 and 0

Correct answer: B. −2 and 2

3 − 6 = −3 (three blocked); +2 = −1 (two woken, one blocked); −1 = −2 (another blocked). A negative value −k means k processes are waiting, so 2 are blocked.

More Operating Systems questions

Exams that ask this topic