GATEverse
← GATE CSE 2018

Q40

MCQ2 marks, −0.67

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:Consumer:do {do { wait (P); wait (R); wait (mutex); wait (mutex); //Add item to buffer //consume item from buffer signal (mutex); signal (mutex); signal (Q); signal (S);}while (1); }while (1);\begin{array}{|l|l|}\hline \text{Producer:} & \text{Consumer:} \\\hline \text{do \{} & \text{do \{} \\ \quad\text{ wait (P);} & \quad\text{ wait (R);} \\ \quad\text{ wait (mutex);} & \quad\text{ wait (mutex);} \\ \quad \text{ //Add item to buffer} & \quad \text{ //consume item from buffer} \\ \quad\text{ signal (mutex);} & \quad\text{ signal (mutex);} \\ \quad \text{ signal (Q);} & \quad\text{ signal (S);} \\ \text{\}while (1); }& \text{\}while (1);} \\ \hline \end{array}

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

Sign in to save attempts.

Loading…