Multiple choice

Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The codes for the processes P and Q are shown below. Process P: Process Q: while (1) { while (1) { W: Y: print '0'; print '1'; print '0'; print '1'; X: Z: } } Synchronization statements can be inserted only at points W, X, Y and Z

Which of the following will always lead to an output starting with '001100110011'?

  1. P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1

  2. P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0

  3. P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1

  4. P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation