CS FundamentalsHardProduct-company MCQ pattern

Producer–consumer with semaphores mutex = 1, empty = N, full = 0. The producer is written as:

Producer–consumer with semaphores mutex = 1, empty = N, full = 0. The producer is written as:
wait(mutex);
wait(empty);
/* add item */
signal(mutex);
signal(full);
The consumer is correct (wait(full); wait(mutex); … signal(mutex); signal(empty);). What can go wrong?
  1. A. Nothing; the order of the two waits does not matter
  2. B. Deadlock when the buffer is full: the producer holds mutex while blocked on empty, so the consumer can never enter
  3. C. Two producers can add items at the same time
  4. D. The consumer can remove from an empty buffer

Correct answer: B. Deadlock when the buffer is full: the producer holds mutex while blocked on empty, so the consumer can never enter

If the buffer is full, the producer acquires mutex and then blocks on empty. The consumer passes wait(full) but blocks on wait(mutex), so neither can proceed. The counting semaphore must be waited on before the mutex.

More Operating Systems questions

Exams that ask this topic