#Monitor
A monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) for a certain condition to become true. Monitors are designed to be used safely in concurrent environments.
A monitor consists of a mutex and condition variables.
- Mutual Exclusion: only one thread calls and gets access to the monitor method at a time
- Condition Synchronization: Threads can wait on condition variables if they can’t proceed
- Signaling: Threads can signal or broadcast to wake up sleeping threads when conditions change
- Automatic Release: The lock is automatically released when a thread exits the monitor or waits on a condition
Examples: