GATE - 2006 | OS | The wait and signal operations of a monitor are implemented using

GATE - 2006 | OS | The wait and signal operations of a monitor are implemented using
Posted on 18-02-2022

GATE - 2006 [Operating System]

Question:

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.

The body of each procedure that is visible outside the monitor is replaced with the following:

 

 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,

   

A

P(x_sem), V(next)

B

V(next), P(x_sem)

C

P(next), V(x_sem)

D

P(x_sem), V(x_sem)

    

Solution:

Option (D) is Correct.

x_count is the no. of processes waiting on semaphore x_sem, initially 0.


x_count is incremented and decremented in x_wait, which shows that in between them wait(x_sem) must happen which is P(x_sem).

Correspondingly V(x_sem) must happen in x_signal.

So, D choice.

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