• edited by
2,169 views
2 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 ______

3 Answers

Best answer
8 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 1 vote

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 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:
Position:
Show:

Related questions

2 2 votes
1 answers 1 answer
645
645 views
Bikram asked Dec 26, 2016
645 views
Consider the following 3 processes with 3 binary semaphores with initial values $S_{0}=0, S_{1}=0, S_{2}=1$$$ \begin{array}{|c|c|c|} \hline \textbf{P} & \textbf{Q} & \tex...
1 1 vote
2 answers 2 answers
2.1k
2.1k views
Bikram asked Dec 26, 2016
2,104 views
Consider the $2$ – process solution to the Critical Section problem (here i refers to the current process and j is the other process )Process Pirepeat flag[i] = true; whi...
2 2 votes
3 answers 3 answers
3.2k
3.2k views
Bikram asked Dec 26, 2016
3,158 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 ...
0 0 votes
1 answers 1 answer
1.2k
1.2k views
Bikram asked Dec 26, 2016
1,247 views
A moving arm disk-storage device has the following specifications. Number of tracks per recording surface – $200$ Disk – rotation speed – $2400$ rpm Track storage capacit...