Each Process is coded as follows
repeat
P(mutex)
{Critical section}
V(mutex)
foreverThe code for 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?
View worked solution
Answer: D
Let us analyze the behavior of the processes. Typically, a semaphore mutex used for mutual exclusion is initialized to .
For processes to , the code is:
repeat
P(mutex)
{Critical Section}
V(mutex)
forever
For process , replacing the entry P(mutex) with V(mutex) gives:
repeat
V(mutex)
{Critical Section}
V(mutex)
forever
Step-by-Step Execution Trace:
- Initially,
mutex = 1. - Process executes its entry operation
V(mutex). SinceVis an increment operation,mutexbecomes . enters the critical section. - Inside the loop, can execute
V(mutex)again at the exit, makingmutex = 3. - Since does not have any blocking
P(mutex)operation, it can loop repeatedly, executingV(mutex)each time and increasing the value ofmutexarbitrarily high (e.g., or more). - With
mutex ≥ 9, all other nine processes ( to ) can execute theirP(mutex)operations without blocking and enter the critical section simultaneously.
Thus, all processes can be inside the critical section at the same time. Since is not listed in options A, B, or C, the correct option is D (None of the above).
Free practice · Your answers on this page are not saved.
