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?
- A. 0 and 4
- B. −2 and 2
- C. −3 and 3
- 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
- Binary semaphore mutex = 1 protects a counter. A programmer mistakenly writes signal(mutex); / critical section / wait(mutex); in every…
- In the dining philosophers problem with 5 philosophers, each picks up the LEFT fork and then the RIGHT fork. Which change by itself…
- Readers–writers with readers' preference: semaphores mutex = 1 (protects readcount), wrt = 1. Reader: wait(mutex); readcount++; if…
- A bounded buffer of size N uses semaphores empty = N, full = 0, mutex = 1. Producer: wait(empty); wait(mutex); add; signal(mutex)…
- Monitors versus semaphores: in a Hoare-style monitor, when a process executes x.signal() and some process is waiting on condition x, which…
- Why must a Mesa-style condition wait be written as while (!cond) wait(c); rather than if (!cond) wait(c);?