| Copyright | (c) The University of Glasgow 2001 |
|---|---|
| License | BSD-style (see the file libraries/base/LICENSE) |
| Maintainer | libraries@haskell.org |
| Stability | experimental |
| Portability | non-portable (concurrency) |
| Safe Haskell | None |
| Language | Haskell2010 |
Control.Concurrent.MVar.Strict
Contents
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
- data MVar a
- newEmptyMVar :: IO (MVar a)
- newMVar :: NFData a => a -> IO (MVar a)
- takeMVar :: MVar a -> IO a
- putMVar :: NFData a => MVar a -> a -> IO ()
- readMVar :: NFData a => MVar a -> IO a
- swapMVar :: NFData a => MVar a -> a -> IO a
- tryTakeMVar :: MVar a -> IO (Maybe a)
- tryPutMVar :: NFData a => MVar a -> a -> IO Bool
- isEmptyMVar :: MVar a -> IO Bool
- 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 :: MVar a -> IO () -> IO ()
MVars
newEmptyMVar :: IO (MVar a) #
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:
putMVaris single-wakeup. That is, if there are multiple threads blocked inputMVar, and theMVarbecomes empty, only one thread will be woken up. The runtime guarantees that the woken thread completes itsputMVaroperation.- 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 usingMVars.
tryTakeMVar :: MVar a -> IO (Maybe a) #
tryPutMVar :: NFData a => MVar a -> a -> IO Bool Source #
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 :: MVar a -> IO Bool #
withMVar :: NFData a => MVar a -> (a -> IO b) -> IO b Source #
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 b Source #
A slight variation on modifyMVar_ that allows a value to be
returned (b) in addition to the modified value of the MVar.
addMVarFinalizer :: MVar a -> IO () -> IO () #