GATE - 1997 | OS | Each Process Pi, i= 1…….9 is coded as follows

GATE - 1997 | OS | Each Process Pi, i= 1…….9 is coded as follows
Posted on 01-03-2022

GATE - 1997 [Operating System]

Question:

Each Process Pi, i= 1…….9 is coded as follows

 repeat 
    P(mutex)
    {Critical section}
    V(mutex)
 forever

The code for P10 is identical except it uses V(mutex) in place of P(mutex). What is the largest number of processes that can be inside the critical section at any moment?
(A) 1
(B) 2
(C) 3
(D) None of above

Solution:

Option (D) is Correct.

Since the both code (i.e., P1 to P9 and P10) can be executed any number of times and code for P10 is
repeat
{
V(mutex)
C.S.
V(mutex)
}
forever
Now, let me say P1 is in CS then P1 is in CS
then P10 comes and executes CS (upon mutex).
Now, P2 comes (down on mutex).
Now P10 moves out of CS (again binary semaphore will be 1).
Now P3 comes (down on mutex).
Now P10 comes (upon mutex).
Now P4 comes (down mutex).
⁞ So, if we take P10 'in' and 'out' of CS recursively, all 10 processes can be in CS at same time using binary semaphore only.

 

Thank You