NTA-UGC-NET 2021 Dec & 2022 June Paper-1
October 21, 2023Digital-Logic-Design
October 21, 2023Operating-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?
The producer will be able to add an item to the buffer, but the consumer can never consume it. | |
The consumer will remove no more than one item from the buffer. | |
Deadlock occurs if the consumer succeeds in acquiring semaphore s when the buffer is empty. | |
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.
Subscribe
Login
0 Comments