... continued
This lesson explains implementing a bounded buffer using the Semaphore class.
We'll cover the following...
Semaphore Implementation
We can also implement the bounded buffer problem using a semaphore. Let's revisit the Semaphore
's constructor. It takes in the initial number of permits and the maximum number of permits. We can use two semaphores, one semConsumer
and the other semProducer
. The trick is to initialize semProducer
semaphore with a maximum number of permits equal to the size of the buffer and set all permits as ...