Control.Concurrent.STM.TMVar
(GHC only)
TMVars
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.
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.
writeTMVar :: TMVar a -> a -> STM () Source #
Non-blocking write of a new value to a TMVar
Puts if empty. Replaces if populated.
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
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
if
the Just
aTMVar
was full with contents a
. After tryTakeTMVar
, the
TMVar
is left empty.