...
NTA-UGC-NET 2021 Dec & 2022 June Paper-1
October 21, 2023
Digital-Logic-Design
October 21, 2023
NTA-UGC-NET 2021 Dec & 2022 June Paper-1
October 21, 2023
Digital-Logic-Design
October 21, 2023

Operating-Systems

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);
     addToBuffer();           removeFromBuffer();
     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.
Correct Answer: C
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.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!