GATE Computer Science (CS) 2018 Shift 1 Solved Paper

© examsiri.com
Question : 54 of 65
 
Marks: +1, -0
Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is N. Three semaphores empty, full and mutex are defined with respective initial values of 0, N and 1. Semaphore empty denotes the number of available slots in the buffer, for the consumer to read from. Semaphore full denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by P, Q, R and S, in the code below can be assigned either empty or full. The valid semaphore operations are: wait ( ) and signal ( ).
Producerconsumer
do{
wait{P};
//Add item to buffer
signl(mutex);
signal(Q)
}while(1);
do{
wait(R);
wait(mutex);
//consume item from buffer
signal(mutex);
signal(s);
}while(1);
Which one of the following assignment to P, Q, R and S will yield the correct solution?
Go to Question: