Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2018
Questions

Q40

MCQ2 marks, −0.67Operating systemsMedium

Consider the following solution to the producer-consumer synchronization problem. The shared buffer size is NN. Three semaphores emptyempty, fullfull and mutexmutex are defined with respective initial values of 0,N0, N and 11. Semaphore emptyempty denotes the number of available slots in the buffer, for the consumer to read from. Semaphore fullfull denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by PP, QQ, RR and SS, in the code below can be assigned either emptyempty or fullfull. The valid semaphore operations are: wait()wait() and sigmal()sigmal().

// Producer:
do {
    wait (P);
    wait (mutex);
    //Add item to buffer
    signal (mutex);
    signal (Q);
}while (1);
// Consumer:
do {
    wait (R);
    wait (mutex);
    //consume item from buffer
    signal (mutex);
    signal (S);
}while (1);

Which one of the following assignments tp PP, QQ, RR and SS will yield the correct solution?

Sign in to save attempts.

Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.