Project ForgeSign up free
Operating Systems
Process Synchronization
GATE 2008
Expert

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 P(s) and V(s) as: 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

  • A0 and 0
  • B0 and 1
  • 1 and 0
  • D1 and 1

Explanation

xb protects mutual exclusion for the shared counter s, so it must start AVAILABLE: xb=1. yb is used purely to block waiting processes until explicitly signaled, so no process should be released prematurely: yb=0. This is the standard construction for implementing a counting semaphore from binary semaphores.

Source: GATE CS 2008 (2008)

This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.

Start revising free