The wait and signal operations of a monitor are implemented using semaphores as follows. In the following,
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);
x_count = x_count + 1;
if (next_count > 0)
V(next)
else
V(mutex);
------------------------------------------------------------ E1;
x_count = x_count - 1;
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) |
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