GATE - 2006 | OS | Consider the solution to the bounded buffer producer/consumer

GATE - 2006 | OS | Consider the solution to the bounded buffer producer/consumer
Posted on 18-02-2022

GATE - 2006 [Operating System]

Question:

Consider the solution to the bounded buffer producer/consumer problem by using general semaphores S, F, and E. The semaphore S is the mutual exclusion semaphore initialized to 1. The semaphore F corresponds to the number of free slots in the buffer and is initialized to N. The semaphore E corresponds to the number of elements in the buffer and is initialized to 0. Which of the following interchange operations may result in a deadlock?

  1. Interchanging Wait (F) and Wait (S) in the Producer process
  2. Interchanging Signal (S) and Signal (F) in the Consumer process

A

1 only

B

2 only

C

Neither 1 nor 2

D

Both 1 and 2

Solution:

Option (A) is Correct.

Suppose Wait(F) and Wait(S) are interchanged. And let the slots are full → F=0.


Now if Wait(S) in producer succeeds, then producer will wait for Wait(F) which is never going to succeed as consumer would be waiting for Wait(S).

So deadlock, can happen.


If Signal(S) and Signal(F) are interchanged in consumer, deadlock won't happen. It will just give priority to a producer compared to the next consumer waiting.

Thank You