strict-concurrency-0.2: Strict concurrency abstractionsSource codeContentsIndex
Control.Concurrent.MVar.Strict
Portabilitynon-portable (concurrency)
Stabilityexperimental
Maintainerlibraries@haskell.org
Contents
MVars
Description

Synchronising, strict variables

Values placed in an MVar are evaluated to head normal form before being placed in the MVar, preventing a common source of space-leaks involving synchronising variables.

Synopsis
MVar (MVar)
newEmptyMVar
newMVar :: NFData a => a -> IO (MVar a)
takeMVar
putMVar :: NFData a => MVar a -> a -> IO ()
readMVar :: NFData a => MVar a -> IO a
swapMVar :: NFData a => MVar a -> a -> IO a
tryTakeMVar
tryPutMVar :: NFData a => MVar a -> a -> IO Bool
isEmptyMVar
withMVar :: NFData a => MVar a -> (a -> IO b) -> IO b
modifyMVar_ :: NFData a => MVar a -> (a -> IO a) -> IO ()
modifyMVar :: NFData a => MVar a -> (a -> IO (a, b)) -> IO b
addMVarFinalizer
MVars
MVar (MVar)
newEmptyMVar
newMVar :: NFData a => a -> IO (MVar a)Source
Create an MVar which contains the supplied value.
takeMVar
putMVar :: NFData a => MVar a -> a -> IO ()Source

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.
readMVar :: NFData a => MVar a -> IO aSource
This is a combination of takeMVar and putMVar; ie. it takes the value from the MVar, puts it back, and also returns it.
swapMVar :: NFData a => MVar a -> a -> IO aSource
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.
tryTakeMVar
tryPutMVar :: NFData a => MVar a -> a -> IO BoolSource
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.
isEmptyMVar
withMVar :: NFData a => MVar a -> (a -> IO b) -> IO bSource
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).
modifyMVar_ :: NFData a => MVar a -> (a -> IO a) -> IO ()Source
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.
modifyMVar :: NFData a => MVar a -> (a -> IO (a, b)) -> IO bSource
A slight variation on modifyMVar_ that allows a value to be returned (b) in addition to the modified value of the MVar.
addMVarFinalizer
Produced by Haddock version 2.4.2