• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

GATE | GATE IT 2006 | Question 57

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,

(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)

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments