... continued
This lesson explains implementing a bounded buffer using the Monitor class.
We'll cover the following
Monitor Implementation
We can also implement the bounded buffer using the Monitor
class. In fact, using the Monitor
class saves us from busy-waiting, as a blocked thread can relinquish the monitor until it gets signaled.
Let's implement the enqueue()
method first. We'll define the entire method as a critical section as we manipulate shared data-structures within it. Below is the implementation:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.