GATE - 2003 | OS | Suppose we want to synchronize two concurrent processes P and Q

GATE - 2003 | OS | Suppose we want to synchronize two concurrent processes P and Q
Posted on 23-02-2022

GATE - 2003 [Operating System]

Questions:

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:

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 and Z. Which of the following will always lead to an output staring with '001100110011' ?

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

   

Solution:

Option (B) is correct.


Process P1 will be executed first and then Process P2 can be executed next.
At the process P: W=P(S)
X=V(T)
At the process Q: Y=P(T)
Z=V(S)
Here, S=1, T=0 then the process P executes first and then Q, and both can run on process alternate way start with P.

Thank You

Download App for Free PDF Download

GovtVacancy.Net Android App: Download

government vacancy govt job sarkari naukri android application google play store https://play.google.com/store/apps/details?id=xyz.appmaker.juptmh