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 ensure that the output string never contains a substring of the form 01n 0 or 10n1 where n is odd?
-
- 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 and T initially 1
- P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1
- V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1
- P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
Correct Option: C
To ensure this condition that substring of form 01n0 or 10n1, where n is odd S should be initially 1, we will case only 1 semaphore S.
So at W P(s), at X V(s) whereas at Y P(s), at Z V(s) Hence (c) is correct option.