The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0=1, S1=0, S2=0. Process P0: `while(true){ wait(S0); print '0'; release(S1); release(S2); }` Process P1: `wait(S1); release(S0);` Process P2: `wait(S2); release(S0);` How many times will process P0 print '0'?
- AAt least twice
- BExactly twice
- Exactly thrice
- DExactly once
Explanation
P0's wait(S0) can succeed exactly as many times as S0 gets a value available: once from its initial value (1), and once each from P1's and P2's single one-time release(S0) calls (each unblocked in turn by P0's own release(S1)/release(S2) signals). Since P1 and P2 each execute their release(S0) only ONCE (no loop), P0 can successfully print exactly 3 times before permanently blocking on its 4th wait(S0), with no more releases ever coming.
Source: GATE CS 2010 (2010)
This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.