# GATE - 2008 | OS | The P and V operations on counting semaphores, where s is a counting ## Question:

The P and V operations on counting semaphores, where s is a counting semaphore, are defined as follows:

P(s) : s =  s - 1;
if (s  < 0) then wait;
V(s) : s = s + 1;
if (s <= 0) then wakeup a process waiting on s;

Assume that Pb and Vb the wait and signal operations on binary semaphores are provided. Two binary semaphores Xb and Yb are used to implement the semaphore operations P(s) and V(s) as follows:

P(s) : Pb(Xb);
s = s - 1;
if (s < 0) {
Vb(Xb) ;
Pb(Yb) ;
}
else Vb(Xb);

V(s) : Pb(Xb) ;
s = s + 1;
if (s <= 0) Vb(Yb) ;
Vb(Xb) ;

The initial values of Xb and Yb are respectively

 A 0 and 0 B 0 and 1 C 1 and 0 D 1 and 1

## Solution:

### Option (C) is Correct.

xb must be 1 because both P(s) operation and V(s) operation perform Pb(xb) first.

So if xb=0, then all the process performing these operations will be blocked.

Yb must be '0' initially, because if Yb is '1' initially then two process can be in critical section at the same time.