October 21, 2023
October 21, 2023
October 21, 2023
###### Digital-Logic-Design
October 21, 2023
 Question 50

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

```semaphore n=0;
semaphore s=1;
void producer()          void consumer()
{                        {
while(true)              while(true)
{                        {
produce();               semWait(s);
semWait(s);              semWait(n);
semSignal(s);            semSignal();
semSignal(n);            consume();
}                        }
}                         }
```

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.
Question 50 Explanation:
Answer is (C), because when consumer first access the semaphore ‘s’ it will down (s) and make ‘s’=0, but for semaphore(n), it has to wait for producer to make it 1 but as for producer it can’t access the critical section because the value of s=0, so semWait(s) will not work. So there will be deadlock.
Question 50 Explanation:
Answer is (C), because when consumer first access the semaphore ‘s’ it will down (s) and make ‘s’=0, but for semaphore(n), it has to wait for producer to make it 1 but as for producer it can’t access the critical section because the value of s=0, so semWait(s) will not work. So there will be deadlock.