CS FundamentalsHardGATE CS

A bounded buffer of size N uses semaphores empty = N, full = 0, mutex = 1. Producer: wait(empty); wait(mutex); add; signal(mutex); signal(full). If the CONSUMER is written as wait(mutex); wait(full); remove; signal(mutex); signal(empty), when can the system deadlock?

  1. A. When the buffer is empty and the consumer gets mutex before a producer
  2. B. When the buffer is full and the producer runs first
  3. C. Never; the order of waits does not matter
  4. D. Only when N = 1

Correct answer: A. When the buffer is empty and the consumer gets mutex before a producer

With an empty buffer the consumer holds mutex and blocks on full; the producer then blocks on mutex and can never signal full. Waits on counting semaphores must come before the wait on mutex.

More Operating Systems questions

Exams that ask this topic