edited by
726 views
2 votes
2 votes

Let us initialize counting semaphore $X$ to $5$. Assume that processes  $P_i$ where $i= 1$ to $15$ are coded as follows.

while (1)
{
P (x);
  {
    critical section
   }
V (x);
}

and suppose that $P_{16}$ is coded as follows:

while (1)
{
V (x);
    {
      critical section
    }
P (x);
}

The number of processes can be in the critical section at most at any point of time is ______

edited by

3 Answers

Best answer
8 votes
8 votes


At first P1 to P15 any 5 processes can enter Critical Section because $X = 5$. Each entry does a $P$ operation which decrements $X$ and after 5 $P$ operations $X = 0.$

Now, P16 comes and go to its critical section as $V$ comes first and hence no wait. Now, due to $V$ operation ($X$ incremented) it also allows one more process to enter the critical section as its wait operation - $P$ can now succeed.

Total Number of process is in Critical Section = 1 ( P16)  + 6 (P1 to  P15 ) = 7.

edited by
1 votes
1 votes

In the above case when you run while(-1) , it runs normally like while(1) , that means 

while(-1) is true here ,

 First 5 processes will enter into Critical section and make X=0 , then P16 will enter and make X=1 , causing yet another Process to enter the CS and thus making total number of processes to 7.

PS: had the question been slightly changed to while(0) , then the answer would be 1 as 

none of the process from (P1 - P15) will ever enter the while loop (and will end) , so only P16 will keep entering the loop and incrementing the X value.That way only P16 will be there in the critical section.

0 votes
0 votes
Assume processes can enter as per Process IDs whenever possible.

 

Let $P_1$ to $P_5$ enter the critical section. $X=0$ now.

Let $P_{16}$ enter. $X=1$ now.

Let $P_6$ enyer. $X = 0$ again.

That's it.

 

7 processes can be in the critical section at maximu,=m.
Answer:

Related questions

2 votes
2 votes
3 answers
1
Bikram asked Dec 26, 2016
1,031 views
In a paged memory, the page hit ratio is $0.35$. The time required to service the page fault is $100$ ns. Time required to access a page in primary memory is $10$ ns.The ...
1 votes
1 votes
1 answer
3