(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
p1: P(Empty)
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)
p2: V(Full)
buffer is filled, now it gives signal to consumer that it can start consuming
c1: P(Full)
means here consumer have to wait only if buffer is empty, and it waits for Producer to fill the buffer
c2: V(Empty)
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 you are giving water in a glass to that thirsty man, so you are the producer here.
The man drinks and makes the glass empty. So he is consumer here.
(b) If there are multiple users we can use mutex semaphores so that exclusively one producer or one consumer can enter the Critical section at a time. We need one mutex for the set of producers and nother for the set of consumers.
p1: P(Empty)
P(mutex1)
p2: V(mutex1)
V(Full)
c1: P(Full)
P(mutex2)
c2: V(mutex2)
V(Empty)
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.