Two concurrent processes P and Q execute the following code. Process P:…
2017
Two concurrent processes P and Q execute the following code.
Process P:
while(True){
W: _____
print(‘0’); print(‘0’);
X: _____
}
Process Q:
while(True){
Y: _____
print(‘1’); print(‘1’);
Z: _____
}
Given S and T are binary semaphore variables, and P() and V() as standard “wait” and “signal” functions respectively. What should be the semaphore operations W, X, Y, and Z for the output string: 11001100.....?
- A.
W = P(T), X = V(S), Y = P(S), Z = V(T), S = 1, T = 0
- B.
W = P(T), X = V(S), Y = P(S), Z = V(T), S = T = 1
- C.
W = P(T), X = V(T), Y = P(S), Z = V(S), S = T = 1
- D.
W = P(T), X = V(T), Y = P(S), Z = V(S), S = 1, T = 0
Attempted by 85 students.
Show answer & explanation
Correct answer: A
To get the strict alternating output string 11001100..., Process Q must execute first to print 11, followed by Process P to print 00.
Since Q runs first, its entry semaphore S must be initialized to 1, and P's entry semaphore T must be 0.
Process Q enters using P(S), prints
11, and signals P using V(T) at position Z.Process P enters using P(T) at position W, prints
00, and signals Q using V(S) at position X.
Therefore, the correct mapping is:
W = P(T), X = V(S), Y = P(S), Z = V(T), S = 1, T = 0.
The correct option is A.