The wait and signal operations of a monitor are implemented using semaphores…

GATE · 2006 · IT

The wait and signal operations of a monitor are implemented using semaphores as follows. In the following, 

  • x is a condition variable,

  • mutex is a semaphore initialized to 1,

  • x_sem is a semaphore initialized to 0,

  • x_count is the number of processes waiting on semaphore x_sem, initially 0, next is a semaphore initialized to 0,

  • next_count is the number of processes waiting on semaphore next, initially 0.

P(mutex); 
body of procedure 
if (next_count > 0) 
    V(next); 
else
    V(mutex); 

Each occurrence of x.wait is replaced with the following:

x_count = x_count + 1; 
if (next_count > 0) 
    V(next) 
else
    V(mutex); 
---------------------------------- E1; 
x_count = x_count - 1; 

Each occurrence of x.signal is replaced with the following:

if (x_count > 0) 
{ 
    next_count = next_count + 1; 
 ---------------------------------- E2; 
    P(next), 
    next_count = next_count - 1; 
} 

For correct implementation of the monitor, statements E1 and E2 are, respectively,

  1. A.

    P(x_sem), V(next)

  2. B.

    V(next), P(x_sem)

  3. C.

    P(next), V(x_sem)

  4. D.

    P(x_sem), V(x_sem)

Attempted by 100 students.

Show answer

Correct answer: D

The worked solution is available to enrolled students.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…