| Portability | non-portable (STM, CPP) |
|---|---|
| Stability | provisional |
| Maintainer | wren@community.haskell.org |
| Safe Haskell | Trustworthy |
Control.Concurrent.STM.TMVar.Compat
Description
Compatibility layer for older versions of the stm library.
Namely, we define tryReadTMVar which stm < 2.3.0 lacks. This
module uses Cabal-style CPP macros in order to use the package
versions when available. This isn't actually used by the stm-chans
package, but we provide it anyways since we provide compatibility
layers for TVar and TChan.
Since: 1.3.0
- data TMVar a
- newTMVar :: a -> STM (TMVar a)
- newTMVarIO :: a -> IO (TMVar a)
- newEmptyTMVar :: STM (TMVar a)
- newEmptyTMVarIO :: IO (TMVar a)
- readTMVar :: TMVar a -> STM a
- tryReadTMVar :: TMVar a -> STM (Maybe a)
- takeTMVar :: TMVar a -> STM a
- tryTakeTMVar :: TMVar a -> STM (Maybe a)
- putTMVar :: TMVar a -> a -> STM ()
- tryPutTMVar :: TMVar a -> a -> STM Bool
- swapTMVar :: TMVar a -> a -> STM a
- isEmptyTMVar :: TMVar a -> STM Bool
The TMVar type
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.
Creating TMVars
newTMVarIO :: a -> IO (TMVar a)
IO version of newTMVar. This is useful for creating top-level
TMVars using unsafePerformIO, because using
atomically inside unsafePerformIO isn't
possible.
newEmptyTMVar :: STM (TMVar a)
Create a TMVar which is initially empty.
newEmptyTMVarIO :: IO (TMVar a)
IO version of newEmptyTMVar. This is useful for creating top-level
TMVars using unsafePerformIO, because using
atomically inside unsafePerformIO isn't
possible.
Reading from TMVars
tryReadTMVar :: TMVar a -> STM (Maybe a)
A version of readTMVar which does not retry. Instead it
returns Nothing if no value is available.
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.
Writing to TMVars
tryPutTMVar :: TMVar a -> a -> STM Bool
Other capabilities
isEmptyTMVar :: TMVar a -> STM Bool
Check whether a given TMVar is empty.