0

Why must one use a mutex in addition to a semaphore when using a bounded buffer in producer consumer problem?

Varun Rao
  • 393
  • 1
  • 5
  • 19

1 Answers1

0
empty:semaphore(n)
full: semaphore(0)
mutex: semaphore(1)

"mutex" is used to lock on Buffer.

"full" is used to block consumer if buffer is empty.

"empty" is used to block producer if buffer is full.

That's why you need 3 semaphores.

You can easily google the code so I don't paste it here.

王智寬
  • 415
  • 1
  • 5
  • 17