An MVar (pronounced "em-var") is a synchronising variable, used
for communication between concurrent threads. It can be thought of as
a a box, which may be empty or full.
Check whether a given MVar is empty.
Notice that the boolean value returned is just a snapshot of the state
of the MVar. By the time you get to react on its result, the MVar may
have been filled (or emptied) - so be extremely careful when using
this operation. Use tryTakeMVar instead if possible.
A safe wrapper for modifying the contents of an MVar. Like
withMVar, modifyMVar will replace the original contents
of the MVar if an exception is raised during the operation.
Put a value into an MVar. If the MVar is currently full,
putMVar will wait until it becomes empty.
There are two further important properties of putMVar:
putMVar is single-wakeup. That is, if there are multiple
threads blocked in putMVar, and the MVar becomes empty,
only one thread will be woken up. The runtime guarantees that the
woken thread completes its putMVar operation.
When multiple threads are blocked on an MVar, they are
woken up in FIFO order. This is useful for providing fairness
properties of abstractions built using MVars.
Take a value from an MVar, put a new value into the MVar
and return the value taken. Note that there is a race condition
whereby another process can put something in the MVar after the
take happens but before the put does.
Return the contents of the MVar. If the MVar is
currently empty, takeMVar will wait until it is full. After a
takeMVar, the MVar is left empty.
There are two further important properties of takeMVar:
takeMVar is single-wakeup. That is, if there are multiple
threads blocked in takeMVar, and the MVar becomes full,
only one thread will be woken up. The runtime guarantees that the
woken thread completes its takeMVar operation.
When multiple threads are blocked on an MVar, they are
woken up in FIFO order. This is useful for providing fairness
properties of abstractions built using MVars.
A non-blocking version of putMVar. The tryPutMVar
function attempts to put the value a into the MVar,
returning True if it was successful, or False otherwise.
withMVar is a safe wrapper for operating on the contents of an
MVar. This operation is exception-safe: it will replace the
original contents of the MVar if an exception is raised (see
Control.Exception).