| Portability | non-portable (requires STM) |
|---|---|
| Stability | experimental |
| Maintainer | libraries@haskell.org |
Control.Concurrent.STM.TMVar
Contents
Description
TMVar: Transactional MVars, for use in the STM monad (GHC only)
- data TMVar a
- newTMVar :: a -> STM (TMVar a)
- newEmptyTMVar :: STM (TMVar a)
- newTMVarIO :: a -> IO (TMVar a)
- newEmptyTMVarIO :: IO (TMVar a)
- takeTMVar :: TMVar a -> STM a
- putTMVar :: TMVar a -> a -> STM ()
- readTMVar :: TMVar a -> STM a
- swapTMVar :: TMVar a -> a -> STM a
- tryTakeTMVar :: TMVar a -> STM (Maybe a)
- tryPutTMVar :: TMVar a -> a -> STM Bool
- isEmptyTMVar :: TMVar a -> STM Bool
TMVars
data TMVar a
A TMVar is a synchronising variable, used
for communication between concurrent threads. It can be thought of
as a box, which may be empty or full.
newEmptyTMVar :: STM (TMVar a)
Create a TMVar which is initially empty.
newTMVarIO :: a -> IO (TMVar a)
IO version of newTMVar. This is useful for creating top-level
TMVars using System.IO.Unsafe.unsafePerformIO, because using
atomically inside System.IO.Unsafe.unsafePerformIO isn't
possible.
newEmptyTMVarIO :: IO (TMVar a)
IO version of newEmptyTMVar. This is useful for creating top-level
TMVars using System.IO.Unsafe.unsafePerformIO, because using
atomically inside System.IO.Unsafe.unsafePerformIO isn't
possible.
tryTakeTMVar :: TMVar a -> STM (Maybe a)
A version of takeTMVar that does not retry. The tryTakeTMVar
function returns Nothing if the TMVar was empty, or if
the Just aTMVar was full with contents a. After tryTakeTMVar, the
TMVar is left empty.
tryPutTMVar :: TMVar a -> a -> STM Bool
isEmptyTMVar :: TMVar a -> STM Bool
Check whether a given TMVar is empty.
Notice that the boolean value returned is just a snapshot of
the state of the TMVar. By the time you get to react on its result,
the TMVar may have been filled (or emptied) - so be extremely
careful when using this operation. Use tryTakeTMVar instead if possible.