Correct Answer - Option 4 : wait(F), wait(M)
Concept:
In producer- consumer problem, producer can only produce the items when there is space in the buffer, means it has to wait for the consumer to consume the items. Similarly, consumer can consume the item only when producer produces it.
Explanation:
Given, M = 1, E = n and F =0
Here, semaphore M is for mutual exclusion, semaphore E is for empty space in buffer , semaphore F is used to define the space filled by the producer.
code for producer side:
while (true)
{
Produce()
Wait(E)
Wait(M)
Append()
Signal(M)
Signal(F)
}
Code for consumer side:
while(true){
Wait(F)
Wait(M)
Consume()
Signal(M)
Signal(E)
}