a) In Producer Consumer problem Producer produce item and makes the buffer full and after that Consumer consumes that item and makes the buffer empty
Here b_empty and b_full are two semaphore values
means, Producer have to wait only if buffer is full and it waits for consumer to remove at least one item. (See, Empty being initialized to BUFFSIZE)
buffer is filled, now it gives signal to consumer that it can start consuming
means here consumer have to wait only if buffer is empty, and it waits for Producer to fill the buffer
Now buffer is empty and Empty semaphore gives signal to the producer that it can start filling
It is same as giving water to a thirsty man.
Here u are giving water in a glass to that thirsty man, so u are producer here
and the man drinks and makes the glass empty, so he is consumer here
b) If there are multiple user we can use mutex semaphore, so that exclusively one could enter in Critical section at a time. i.e.
PS: One thing to see is P(mutex) is after P(Full) and P(empty)- otherwise deadlock can happen when buffer is full and a producer gets mutex or if buffer is empty and a consumer gets mutex.