2k views

Suppose we want to synchronize two concurrent processes $P$ and $Q$ using binary semaphores $S$ and $T$. The code for the processes $P$ and $Q$ is shown below.

 Process P: Process Q: while(1) { while(1) { W: Y: print '0'; print '1'; print '0'; print '1'; X: Z: } }

Synchronization statements can be inserted only at points $W, X, Y,$ and $Z$

Which of the following will always lead to an output staring with ‘$001100110011$’?

1. $P(S)$ at $W, V(S)$ at $X, P(T)$ at $Y, V(T)$ at $Z, S$ and $T$ initially $1$

2. $P(S)$ at $W, V(T)$ at $X, P(T)$ at $Y, V(S)$ at $Z, S$ initially $1,$ and $T$ initially $0$

3. $P(S)$ at $W, V(T)$ at $X, P(T)$ at $Y, V(S)$ at $Z, S$ and $T$ initially $1$

4. $P(S)$ at $W, V(S)$ at $X, P(T)$ at $Y, V(T)$ at $Z, S$ initially $1$ , and $T$ initially $0$

edited | 2k views
0
Can you edit the question ? Option B of question 80 has typo ! How can be T be 0 & 1 at same time ?

To get pattern $001100110011$

Process $p$ should be executed first then Process $Q$ should be executed

So, at Process $P$ :  $\mathbf{W}$ $P(S)$   $\mathbf{X}$  $V(T)$

And at Process $Q$ : $\mathbf{Y}$ $P(T)$    $\mathbf{Z}$ $V(S)$

With $\mathbf{S=1}$ and  $\mathbf{T=0}$ initially ( only $\mathbf{P}$ has to be run first then only $\mathbf{Q}$ is run , both process run on alternet way start with $\mathbf{P}$)

edited
+1
Can you edit the question ? Option B of question 80 has typo ! How can be T be 0 & 1 at same time ?
0
Is it possible to get answer "d"..

Explain b option by analysis pls
0

your option Y has problem it should have been P(T)

starting with  001100110011 means alternative sequence of process P and Q..
Process P should start execution so at W, P(s) where S=1..
to get alternate sequence X and Y are operation on same semaphore i.e. T.

option B or C.
bt process Q shouldn't start execution before process P ..
means Initial value T=0

W : P(s)         X : V(T)           Y : P(S)             Z : V(S)
S =  1    T = 0

It cant be C) because If T = 1 then P(T) at Y for process Q can be executed before process P by decrementing T by 1 and print 11... which is not required.
edited
0
why option a is not valid  s = t =1  at W,  P(s) = 0  and at X , print 00 V(S) =1 AGAIN   at Y , P(T) =0 PRINT 11  at  Z V(T) = 1  KINDLY EXPLAIN  is there issue of while loop , in process p  or why we can not prempt  after process P to process Q than  to P  again

1
2