Direction: 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 statement can be inserted only at point W, X, Y and Z
-
Which of the following will always lead to an output string with ‘001100110011’?
-
- P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
- P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0
- P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1
- P(S) at W, V(T) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0
- P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
Correct Option: B
For output string 001100110011 alternatingly we require process P & Q to execute. For this to happen P(s) with S = 1 should be placed at W. At the same time P(T) with T = 0 will be at Y.
At X we have V(T) which will have T = 1 so process Q starts.
At the same time at Z we have V(s) which make S = 0 to stop process P.
Hence (b) is correct option.