The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+16 votes
1.6k 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$

asked in Operating System by Veteran (59.5k points)
edited by | 1.6k views
0
Can you edit the question ? Option B of question 80 has typo ! How can be T be 0 & 1 at same time ?

3 Answers

+22 votes
Best answer

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}$ $V(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}$)

So, answer is (B).

answered by Boss (31.4k points)
edited by
+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
+4 votes
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
answered by Veteran (55.1k points)
+3 votes
Answer is B)

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.
answered by (445 points)
edited by
Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

37,999 questions
45,495 answers
131,568 comments
48,630 users