Even if it’s vice versa then also more than 3 processes can be in C.S. :
The code I’m using for mutex :
Struct BSemaphore
{
enum value(0,1);
Queue type L;
}
P(BSemaphore mutex)
{
if(mutex.value == 1)
mutex.value = 0;
else
put the process in mutex.L;
sleep();
V(BSemaphore mutex)
{
if(mutex.L is empty)
mutex.value = 1;
else
Select a process from mutex.L;
wakeup();
}
}
Sequence :
mutex = 1;
p1 enters makes mutex = 0;
p10 enters makes mutex = 1;
p2 enters makes mutex = 0; // At this point there are 3 processes inside C.S.
p10 leaves , executes p(mutex) , but as it’s already zero goes to sleep and in queue.
p2 leaves executes v(mutex) , makes mutex = 1 and wakeup p10 . // At this point there is only 1 process inside C.S.
p3 enters makes mutex = 0;
p10 enters makes mutex = 1;
p4 enters makes mutex = 0 ; // At this point there are 4 processes inside C.S.
And also answer of this should be 1 , due to two reasons :
1: Mutexes are not binary semaphore , mutex is a locking mechanism and the thread which acquired the lock can only release it.
2: Option d) says None , instead of none of the above.