edited by
26,229 views
61 votes
61 votes

The following program consists of $3$ concurrent processes and $3$ binary semaphores. The semaphores are initialized as $S0=1, S1=0$ and $S2=0.$
$$\begin{array}{|l|l|}\hline \text{Process P0}  &  \text{Process P1} & \text{Process P2} \\ \hline  \text{while (true) \{} & \text{wait (S1);} & \text{wait (S2);} \\  \text{    wait (S0);} & \text{release (S0);} & \text{release (S0);} \\  \text{   print ‘0';} & &  \\  \text{   release (S1);} & & \\  \text{   release (S2);} & \text{} & \text{} \\ \text{\}}  &  \text{}   \\\hline \end{array}$$
How many times will process $P0$ print '$0$'?

  1. At least twice
  2. Exactly twice
  3. Exactly thrice
  4. Exactly once
edited by

6 Answers

0 votes
0 votes
a is most appropriate ans here
0 votes
0 votes
Initial condition : S0=1, S1=0, S2=0,

so process P1 and P2 have to wait and only P0 can execute first.

After completing one iteration of the while loop, 0 is printed once.

Now the semaphore variables are – S0=0, S1=1, S2=1

In the minimalist case – P1 and P2 both will be incrementing S0 in one go, so after both P1 and P2 complete execution,

S0=1, S1=0, S2=0

now again P0 will be executed and print 0.

After that it will set S0=0.

So in the worst case S0 will be printed twice.

S0 willbe printed atleast twice.
Answer:

Related questions

23 votes
23 votes
2 answers
3
41 votes
41 votes
2 answers
4