Suppose we want to synchronize two concurrent processes P P P and Q Q Q using binary semaphores S S S and T T T . The code for the processes P P P and Q Q Q is shown below.
Process P: Process Q: while(1) { while(1) { W: Y: print ‘0’; print ‘1’; print ‘0’; print ‘1’; X: Z: } } \begin{array}{|l|l|}\hline \text{Process P:} & \text{Process Q: } \\\hline \text{ while(1) \{ } & \text{while(1) \{} \\ \text{W:} & \text{Y:} \\ \text{ print ‘0';} & \text{ print ‘1';} \\ \text{ print ‘0';} & \text{ print ‘1';} \\ \text{X:} & \text{Z:} \\ \text{\}} & \text{\}} \\\hline \end{array} Process P: while(1) { W: print ‘0’; print ‘0’; X: } Process Q: while(1) { Y: print ‘1’; print ‘1’; Z: }
Synchronization statements can be inserted only at points W , X , Y , W, X, Y, W , X , Y , and Z Z Z
Which of the following will ensure that the output string never contains a substring of the form 01 n 0 01^n0 0 1 n 0 and 10 n 1 10^n1 1 0 n 1 where n n n is odd?
(A) P ( S ) P(S) P ( S ) at W , V ( S ) W, V(S) W , V ( S ) at X , P ( T ) X, P(T) X , P ( T ) at Y , V ( T ) Y, V(T) Y , V ( T ) at Z , S Z, S Z , S and T T T initially 1 1 1
(B) P ( S ) P(S) P ( S ) at W , V ( T ) W, V(T) W , V ( T ) at X , P ( T ) X, P(T) X , P ( T ) at Y , V ( S ) Y, V(S) Y , V ( S ) at Z , S Z, S Z , S and T T T initially 1 1 1
(C) P ( S ) P(S) P ( S ) at W , V ( S ) W, V(S) W , V ( S ) at X , P ( S ) X, P(S) X , P ( S ) at Y , V ( S ) Y, V(S) Y , V ( S ) at Z , S Z, S Z , S initially 1 1 1
(D) V ( S ) V(S) V ( S ) at W , V ( T ) W, V(T) W , V ( T ) at X , P ( S ) X, P(S) X , P ( S ) at Y , P ( T ) Y, P(T) Y , P ( T ) at Z , S Z, S Z , S and T T T initially 1 1 1