The following program consists of 3 concurrent processes and 3 binary semaphores The semaphore, are initialized as S0=1 S1=0 S2=0
Process P0:
while(1)
{
wait (S0);
print '0';
release (S1);
release (S2);
}
Process P1:
wait(S1);
release (S0);
Process P2:
wait(S2);
release (S0);
How many times will process PO print '0"??
(A) At least twice (b) Exactly tWlce (c) Exactly thrice (d) Exactly once
in this I have a confusion that Process P1 and P2 as will execute once or they will continue after executing once as they are not having while loop like process P0, if they will execute once only then According to me the answer should be (b), and if they will execute again then the answer will be (A)
please help thanks in advance
Initially P0
will execute because only S0=1
. It will print single 0.
Now when S1
and S2
are releases by P0
then any one of them can be executed.
Let us suppose P1 executes and releases S0(Now value of S0 is 1).
Now there are two possibilities either P0
or P2
can execute.
Let us take P2
executes and releases S0
, so at the end P0 execute and print 0 (means two 0's) but if P0
executes before P2
then total of 3 0's will print(one at the time of P0
and then P2
which releases S0
so P0
executes again).
So the perfect answer is at least two 0's.