Question:-
The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0=1, S1=0, S2=0.



Process P0Process P1Process P2
while (true) {
wait (S0);
print ‘0’
release (S1);
release (S2);
}
wait (S1);
Release (S0);
wait (S2);
release (S0);

How many times will process P0 print ‘0’?
Option (A)
At least twice
Option (B)
Exactly twice
Option(C)
Exactly thrice
Option(D)
Exactly once
Correct Option:
(A)
Question Solution:
Initially neither P1 nor P2 can go, only P0 can go since It uses the semaphore so whose value is ‘1’ It prints ‘0’ then, after releasing s1, s2, again either P1 or P2 releases ‘S0 so that it will go to print ‘0’ at least twice
question-answer-faq-2249