839 views
5 votes
5 votes

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

5 Answers

Best answer
7 votes
7 votes
Answer is 3

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
selected by
3 votes
3 votes

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
2 votes
2 votes
Answer is - c) 3
0 votes
0 votes
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.
Answer:

Related questions

1 votes
1 votes
2 answers
2