0

I'm currently studying how producer/consumer process works. Here we are given the following shared data structures, mutex, empty, and full. We have the codes for the producer, consumer, wait, and signal.

Below those code is my assumption. I try to explain the logic behind both the producer and consumer process. What I don't understand is why do we need the semaphore mutex? Is it so that only 1 process is able to consume from the buffer at a time?

enter image description here

asilvester635
  • 81
  • 2
  • 13
  • What happens to the data being read if the producer writes to the buffer while the consumer is reading from the buffer? If you answer that question you will know why the mutex is required. – Jim Rogers Oct 16 '17 at 18:21
  • @JimRogers so the mutex protects the critical region and thus prevents race conditions. – asilvester635 Oct 16 '17 at 18:36

0 Answers0