Skip to content
Official PYQ · 2008

GATE CS 2008 Q63 — Concurrency and Synchronization

Explain with AI

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

P(s):P(s):

s=s−1;s=s-1;
If s<0s < 0 then wait;

V(s):V(s):

s=s+1;s=s+1;
If s≤0s \leq0 then wake up process waiting on s;

Assume that PbP_b and VbV_b the wait and signal operations on binary semaphores are provided. Two binary semaphores xbx_b and yby_b are used to implement the semaphore operations P(s)P(s) and V(s)V(s) as follows:

P(s):P(s): 

Pb(xb);\quad P_b(x_b);
s=s−1;\quad s = s-1;
if (s<0)\quad \text{if } (s<0)
{\quad \{
Vb(xb);\qquad V_b(x_b);
Pb(yb);\qquad P_b(y_b);
}\quad \}
 else Vb(xb);\quad \text{ else } V_b(x_b);

V(s):V(s): Pb(xb);\quad P_b(x_b);
s=s+1;\quad s= s+1;
if (s≤0)Vb(yb);\quad \text{if } (s\leq0) V_b(y_b) ;
Vb(xb);\quad V_b(x_b);

The initial values of xbx_b and yby_b are respectively

Choose one option
View worked solution

Answer: C

To determine the initial values of the binary semaphores xbx_b and yby_b, let us analyze their roles in the implementation of the counting semaphore operations:

  1. Role of xbx_b:

    The variable ss is a shared integer representing the semaphore count. In both P(s)P(s) and V(s)V(s), the operations on ss (such as decrementing, incrementing, and checking its value) must be executed atomically to prevent race conditions.

    The binary semaphore xbx_b is used to provide mutual exclusion (acting as a mutex) around these critical sections. Since a process must be allowed to enter the critical section initially, the mutex xbx_b must be initialized to 11.

  2. Role of yby_b:

    The binary semaphore yby_b is used to block processes when the resource count ss is less than 00.

    When a process calls P(s)P(s) and finds s<0s < 0, it releases the mutex xbx_b and then executes Pb(yb)P_b(y_b) to block itself. For the process to successfully block at Pb(yb)P_b(y_b), the semaphore yby_b must be unavailable initially. Thus, yby_b must be initialized to 00.

    When another process calls V(s)V(s) and increments ss such that s≤0s \le 0, it signals Vb(yb)V_b(y_b) to wake up one of the blocked processes.

Therefore, the initial values of xbx_b and yby_b are 11 and 00 respectively.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Concurrency and Synchronization questions