Concurrent threads are synchronized by monitors. A monitor is a set of functions in which only one thread may execute at a time. It is possible for a thread running inside a monitor to suspend its execution so that another thread may enter the monitor. The initial thread waits for the second one to notify it (for example, that a resource is now available) and then to exit the monitor.
The MONITOR API is summarized in the following table:
Function |
Description |
---|---|
monitorGet() |
Obtains the lock on the given monitor |
monitorInit() |
Initializes the given monitor |
monitorNotify() |
Notifies one thread waiting in monitorWait() |
monitorNotifyAll() |
Notifies all threads waiting in monitorWait() |
monitorRel() |
Releases a lock on a given monitor |
monitorWait() |
Causes a thread that owns the lock on the given monitor to suspend itself until it receives notification from another thread |