Semaphores S and T. The code for the processes P and Q is shown below.…
2004
Semaphores S and T. The code for the processes P and Q is shown below. 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'?
Process P | Process Q |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Answer: B. P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0 — Initialize semaphores S=1 and T=0. Insert V(T) at point X to release Process Q after Process P prints the first '0'. Insert V(S) at point Z to allow Process P…
- A.
P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
- B.
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0
- C.
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1
- D.
P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0
Attempted by 101 students.
Show answer & explanation
Correct answer: B
Initialize semaphores S=1 and T=0. Insert V(T) at point X to release Process Q after Process P prints the first '0'. Insert V(S) at point Z to allow Process P to resume after Process Q prints the second '1'. This configuration ensures the sequence 0, 0, 1, 1 repeats indefinitely.
A video solution is available for this question — log in and enroll to watch it.
Explore the full course: Iocl Engineers Officers Grade A Paper 2