Correct Answer - Option 1 : At least twice
The correct answer is option 1
Concept:
Binary semaphore which can take only two values 0 and 1 and ensure mutual exclusion.
A process is entered into the critical section only when the value of semaphore(s) = 1
Otherwise, it will wait until semaphore(s) >0
Explanation:
The semaphores are initialized as S0=1, S1=0, S2=0.
Because S0 =1 then P0 enter into the critical section and other processes will wait until either S1=1 or S2 =1
The minimum number of times 0 printed:
- S0 =1 then P0 enter into the critical section
- print '0'
- then release S1 and S2 means S1 =1 and s2 =1
- now either P1 or P2 can enter into the critical section
- if P1 enter into the critical section
- release S0
- then P2 enter into the critical section
- release S0
- P1 enter into the critical section
- print '0'
The minimum number of time 0 printed is twice when executing in this order (p0 -> p1 -> p2 -> p0)
The Maximum number of times 0 printed:
- S0 =1 then P0 enter into the critical section
- print '0'
- Then release S1 and S2 means S1 =1 and s2 =1
- Now either P1 or P2 can enter into the critical section
- If P1 enter into the critical section
- Release S0 means S0 =1
- S0 =1 then P0 enter into the critical section
- print '0'
- Then P2 enter into the critical section
- Release S0 means S0 =1
- S0 =1 then P0 enter into the critical section
- print '0'
Maximum no. of time 0 printed is thrice when execute in this order (p0 -> p1 -> p0 -> p2 -> p0)
So, At least twice will process P0 print ‘0’