465 views

Each process $P_i$, where $i= 1$ to $9$ is coded as follows

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

The code for $P_{10}$ is identical except that it uses $V$ (mutex) instead of $P$ (mutex) and vice-verse. What is the largest number of processes that can be inside the critical section at any moment if initial value of the semaphore is 1?

1. 1
2. 2
3. 3
4. none

the correct answer should be 10

@MiNiPanda

Here also repeat forever then why we cant use P10 more than one time ?

let  first P10 takes  lock  and issues signal so semaphore value will become 2 now P10( it signals first) & any two of P1 to P9 process can be in critical section at max

P1 to P9 using:

P10 using
1. repeat
2. P (mutex)
3. {critical section }
4. V (mutex)
5. foreve
1. repeat
2. V (mutex)
3. {critical section }
4. P (mutex)
5. foreve
Run 1st for any process. make mutex= 0  Run 2nd for any process, makes mutex= 1

Now 3rd time run for any process , makes mutex = 0

Since this code for only P10 so no more process can enter

### 1 comment

Why not p10 will again come back and execute again and make mutex 1??

### 1 comment

Please explain it, it is counfusing between gateoverflow.in/66221/go2017-os-9
when p1  came into c.s it will be preempted and then p10 will come and increment the mutex value by 1 and then it will release the cs and now p3 can come into the cs and again p3 will be preempt after coming into cs so now again p10 will come and increment the mutex value by 1 and like this every process will come into critical section at a time.
by

Are you referring to this question?

https://gateoverflow.in/2264/gate1997_6-8

But there is a change in the given one.

in https://gateoverflow.in/2264/gate1997_6-8 , P(mutex) is replaced by V(mutex), but,in https://gateoverflow.in/66221/go2017-os-9, they are interchanged. Here max 3 processes can only come into CS.