The Producer/Consumer (Bounded Buffer) Problem
Remember the producer/consumer problem from the previous chapter? Let's try to solve it with semaphores!
We'll cover the following
The next problem we will confront in this chapter is known as the producer/consumer problem, or sometimes as
First attempt
Our first attempt at solving the problem introduces two semaphores, empty
and full
, which the threads will use to indicate when a buffer entry has been emptied or filled, respectively. The code for the put and get routines is given below:
Get hands-on with 1400+ tech skills courses.