Q40
MCQ2 marks, −0.67Operating systemsMediumConsider the following solution to the producer-consumer synchronization problem. The shared buffer size is . Three semaphores , and are defined with respective initial values of and . Semaphore denotes the number of available slots in the buffer, for the consumer to read from. Semaphore denotes the number of available slots in the buffer, for the producer to write to. The placeholder variables, denoted by , , and , in the code below can be assigned either or . The valid semaphore operations are: and .
// 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 , , and will yield the correct solution?
Keys: A–D or 1–4 choose, Enter checks, ← → move between questions.
Solutions and discussion are hidden while you attempt this question. They open once you check or show the answer.