GATE - 2014 | OS | Consider the procedure below for the Producer-Consumer problem which

GATE - 2014 | OS | Consider the procedure below for the Producer-Consumer problem which
Posted on 11-02-2022

GATE - 2014 [Operating System]

Question:

Consider the procedure below for the Producer-Consumer problem which uses semaphores: 

Consider the procedure below for the Producer-Consumer problem which uses semaphores:  Which one of the following is TRUE? 

Which one of the following is TRUE?

A

The producer will be able to add an item to the buffer, but the consumer can never consume it.

B

The consumer will remove no more than one item from the buffer.

C

Deadlock occurs if the consumer succeeds in acquiring semaphore s when the buffer is empty.

D

The starting value for the semaphore n must be 1 and not 0 for deadlock-free operation.

  

Solution:

Option (C) is Correct.

because when the consumer first access the semaphore 'S' it will down (S) and make 'S'=0,

but for semaphore(n), it has to wait for the producer to make it 1 but as for the producer, it can't access the critical section because of the value of S=0, so semwait(S) will not work.

So there will be deadlock.

Thank You

Download App for Free PDF Download

GovtVacancy.Net Android App: Download

government vacancy govt job sarkari naukri android application google play store https://play.google.com/store/apps/details?id=xyz.appmaker.juptmh