CS FundamentalsHardGATE CS (PYQ pattern)

A 2-slot bounded buffer uses mutex = 1, empty = 2, full = 0. Two producers each insert 2 items with the (buggy) code wait(mutex); wait(empty); insert, print p; signal(mutex); signal(full). One consumer removes 3 items with the correct code wait(full); wait(mutex); remove, print c; signal(mutex); signal(empty). All three start together. Which statement is correct?

  1. A. No deadlock is possible, because the consumer still waits on full before mutex
  2. B. Deadlock is possible, and every deadlock occurs with the buffer full
  3. C. Deadlock is possible only when the buffer is empty
  4. D. Deadlock is possible only after all 3 items have been consumed

Correct answer: B. Deadlock is possible, and every deadlock occurs with the buffer full

A producer that holds mutex and blocks on empty (buffer full) stops the consumer, which needs mutex to remove an item. Exhaustive exploration finds deadlocks after outputs pp, ppcp and pcpp: each has 2 items in the buffer and a producer holding mutex. With the buffer not full, wait(empty) succeeds at once, so no other deadlock exists. 8 complete outputs remain possible as well.

More Operating Systems questions

Exams that ask this topic