BOUNDED BUFFER
PROBLEM
Presented By
Vaishnupriya.S
1912034
BOUNDED BUFFER PROBLEM
Bounded Buffer Problem also called as producer consumer problem
It is a synchronization problem.
Producer is producing some items and enters them into the buffer.
The consumer removes the items from the buffer and consumes them.
The same memory buffer is shared by both producers and consumers
which is of fixed-size.
A producer should not produce items into the buffer when the consumer is
consuming an item from the buffer and vice versa. So the buffer should
only be accessed by the producer or consumer at a time.
Accessing memory buffer should not be allowed to producer and
consumer at the same time.
THE PRODUCER CONSUMER PROBLEM
WITH DIAGRAM
SEMAPHORE
A semaphore S is an integer variable that can be accessed only through two
standard operations
[Link] wait() operation reduces the value of semaphore by 1 .
[Link] signal() operation increases its value by 1.
BOUNDED-BUFFER PROBLEM PROCESS
Shared data:
semaphore full, empty, mutex;
Initialization:
full = 0, empty = n, mutex = 1
PRODUCER PROCESS
do {
produce an item in nextp
…
wait(empty);
wait(mutex);
…
add nextp to buffer…
signal(mutex);
signal(full);
} while (1);
CONSUMER PROCESS
do {
wait(full)
wait(mutex);
…
remove an item from buffer to nextc
…
signal(mutex);
signal(empty);
…
consume the item in nextc
…
} while (1);
APPLICATION
A Pipe or other finite queue (buffer), is an example of the bounded buffer
problem.
THANK YOU