monitor(@optional name = void)
Return a new monitor.
A monitor represents a set of blocked tasks. These blocked tasks are waiting for a certain
condition to become true
. When a task modifies some program state that might make
the condition true
, the task unblocks some number of tasks (one or all depending on the primitive used)
so they can check if the condition is now true
. This allows complex forms of intertask
synchronization to be expressed more conveniently than with mutexes alone.
Each monitor has a specific field which can be used in an application specific way to associate data with the condition variable.
let mx, mn = mutex(), monitor()
!{ mutex_lock(mx)
mutex_unlock(mx, mn)
showln("done...") }
!{ mutex_lock(mx)
mutex_unlock(mx, mn)
showln("bye.") }
!monitor_broadcast(mn)
//> done...
bye.