Producer and consumer
Producer and consumer
figure
So, what are the Producer-Consumer Problems?
Producer Process should not insert any data when the buffer is full.
Consumer Process should not remove any data when the buffer is empty.
Producer and consumer should not insert and remove data simultaneously.
Empty
Empty is a semaphore variable that is used for maintaining the count of the empty slots in the
buffer, initially all slots are empty
Full:- Full is a semaphore variable that is used for maintaining the count of the filled slots in the
buffer, initially no space is filled by the Producer process.
Mutex:-mutex is a binary semaphore variable that has a value of 0 or 1.Which is used
to acquire and release the lock
We will use the Signal() and wait() operation in the above-mentioned semaphores to solve the
Producer-Consumer problem.
Signal() - The signal function increases the semaphore value by 1. Wait() - The wait operation
decreases the semaphore value by 1.