in Operating System edited by
130 views
1 vote
1 vote

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$
in Operating System edited by
by
130 views

3 Comments

A , C , D options are same
0
0
@Bikram Sir In test question is not aligned properly.
0
0
@shivesh

now it is ok , i think.
0
0

1 Answer

2 votes
2 votes
Best answer

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