There is one Producer in the producer-consumer problem, Producer is producing some items, whereas there is one Consumer that is consuming the items produced by the Producer. The same memory buffer is shared by both producers and consumers which is of fixed-size. The following problems occur in this scenario: a) The producer should produce data only when the buffer is not full. In case it is found that the buffer is full, the producer is not allowed to store any data into the memory buffer. b) Data can only be consumed by the consumer if and only if the memory buffer is not empty. In case it is found that the buffer is empty, the consumer is not allowed to use any data from the memory buffer. c) Accessing memory buffer should not be allowed to producer and consumer at the same time. How can you use semaphores to solve each of the above mentioned problems? Explain.
There is one Producer in the producer-consumer problem, Producer is producing some items,
whereas there is one Consumer that is consuming the items produced by the Producer. The
same memory buffer is shared by both producers and consumers which is of fixed-size. The
following problems occur in this scenario:
a) The producer should produce data only when the buffer is not full. In case it is found
that the buffer is full, the producer is not allowed to store any data into the memory
buffer.
b) Data can only be consumed by the consumer if and only if the memory buffer is not
empty. In case it is found that the buffer is empty, the consumer is not allowed to use
any data from the memory buffer.
c) Accessing memory buffer should not be allowed to producer and consumer at the
same time. How can you use semaphores to solve each of the above mentioned
problems? Explain.
Step by step
Solved in 2 steps