GATE CS 2014, set 2 · Question 41 · Operating System · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

Consider the procedure below for the Producer-Consumer problem which uses semaphores:
semaphore n = 0; semaphore s = 1; void producer() { while(true) { produce(); semWait(s); addToBuffer(); semSignal(s); semSignal(n); } } void consumer() { while(true) { semWait(s); semWait(n); removeFromBuffer(); semSignal(s); consume(); } }
Which one of the following is TRUE ?

  1. (A) The producer will be able to add an item to the buffer, but the consumer can never consume it.
  2. (B) The consumer will remove no more than one item from the buffer.
  3. (C) Deadlock occurs if the consumer succeeds in acquiring semaphore s when the buffer is empty.
  4. (D) The starting value for the semaphore n must be 1 and not 0 for deadlock-free operation.
Answer

Answer (C)

Answer from the official GATE CS 2014 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes