edited by
264 views
2 votes
2 votes

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} & \textbf{R}  \\ \hline \text{while(1)} & \text{while(1)} & \text{while(1)} \\  \{  & \{ & \{  \\  P(S_{0}); & P(S_{1}); & P(S_{2}); \\ \text{Print(0);} & \text{Print(1);} & \text{Print(2);} \\  V(S_{1}); &  V(S_{1}); & V(S_{0}); \\  \}  & \} & \}   \\ \hline \end{array}$$

What will be the correct pattern generated by these $3$ processes?

  1. $211$
  2. $200$
  3. $210$
  4. $201$
edited by

1 Answer

Best answer
2 votes
2 votes

Always R will be executed 1st as S2=1. Then after that, 2 will be printed and  S0  will become 1 by executing V(s0).
Then P will be executed as S0 is 1 . 0 is printed. S=0, S1=1, S2=0.
Next  Q will be executed as S1 is 1  . 1 is printed. S0=0, S1=1, S2=0.


So after this only Q can be executed, resulting the pattern 201.

selected by
Answer:

Related questions

2 votes
2 votes
3 answers
1
Bikram asked Dec 26, 2016
1,050 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
Bikram asked Dec 26, 2016
203 views
A counting semaphore is initialized to $10$. The $6$ P(wait) operations and $4$ V(signal) operations were completed in this semaphore. The resulting value of semaphore is...
0 votes
0 votes
1 answer
4