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…?
- AOption (a)
W = P (T), X = V(S), Y = P(S), Z = V (T), S = T = 1
- BOption (b)
W = P (T), X = V(T), Y = P(S), Z = V(S), S = T = 1
- COption (c)
W = P (T), X = V (T), Y = P(S), Z = V(S), S = 1, T = 0
- DOption (d)
W = P(T), X = V(S), Y = P(S), Z = V(T), S = 1, T = 0
View answer & explanationHide answer & explanation
Correct answer
W = P(T), X = V(S), Y = P(S), Z = V(T), S = 1, T = 0
Why this answer is correct
For the output string: 11001100…….
We have to take,
For process P:
W = P(T)
X = V (S)
For process q:
Y = P(S)
Z = V (T), where, S = 1 and T = 0
So, in this when we try to execute process P, it will go to P(T) as T = 0, it cannot enter into critical section.
So, we try to execute process Q.
It will go to P(S), As S = 1, so process q will enter into critical section and make S = 0 and print 11, then after its exit from critical section only, we can execute process P and print 00.
So, both process P and Q depends on each other to enter the critical section. In this way, it prints the sequence 11001100……
