Copyright | (c) The University of Glasgow 2004 |
---|---|
License | BSD-style (see the file libraries/base/LICENSE) |
Maintainer | [email protected] |
Stability | experimental |
Portability | non-portable (requires STM) |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
(GHC only)
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.
newTMVar :: a -> STM (TMVar a) Source
Create a TMVar
which contains the supplied value.
newEmptyTMVar :: STM (TMVar a) Source
Create a TMVar
which is initially empty.
newTMVarIO :: a -> IO (TMVar a) Source
IO
version of newTMVar
. This is useful for creating top-level TMVar
s using unsafePerformIO
, because using atomically
inside unsafePerformIO
isn't possible.
newEmptyTMVarIO :: IO (TMVar a) Source
IO
version of newEmptyTMVar
. This is useful for creating top-level TMVar
s using unsafePerformIO
, because using atomically
inside unsafePerformIO
isn't possible.
takeTMVar :: TMVar a -> STM a Source
Return the contents of the TMVar
. If the TMVar
is currently empty, the transaction will retry
. After a takeTMVar
, the TMVar
is left empty.
putTMVar :: TMVar a -> a -> STM () Source
Put a value into a TMVar
. If the TMVar
is currently full, putTMVar
will retry
.
readTMVar :: TMVar a -> STM a Source
This is a combination of takeTMVar
and putTMVar
; ie. it takes the value from the TMVar
, puts it back, and also returns it.
tryReadTMVar :: TMVar a -> STM (Maybe a) Source
A version of readTMVar
which does not retry. Instead it returns Nothing
if no value is available.
Since: stm-2.3
swapTMVar :: TMVar a -> a -> STM a Source
Swap the contents of a TMVar
for a new value.
tryTakeTMVar :: TMVar a -> STM (Maybe a) Source
A version of takeTMVar
that does not retry
. The tryTakeTMVar
function returns Nothing
if the TMVar
was empty, or Just a
if the TMVar
was full with contents a
. After tryTakeTMVar
, the TMVar
is left empty.
tryPutTMVar :: TMVar a -> a -> STM Bool Source
A version of putTMVar
that does not retry
. The tryPutTMVar
function attempts to put the value a
into the TMVar
, returning True
if it was successful, or False
otherwise.
isEmptyTMVar :: TMVar a -> STM Bool Source
Check whether a given TMVar
is empty.
mkWeakTMVar :: TMVar a -> IO () -> IO (Weak (TMVar a)) Source
Make a Weak
pointer to a TMVar
, using the second argument as a finalizer to run when the TMVar
is garbage-collected.
Since: stm-2.4.4
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.8.3/docs/html/libraries/stm-2.5.0.0/Control-Concurrent-STM-TMVar.html