TMVar

module Control.Concurrent.STM.TMVar
stm Control.Concurrent.STM.TMVar
TMVar: Transactional MVars, for use in the STM monad (GHC only)
data TMVar a
stm Control.Concurrent.STM.TMVar
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.
putMVar :: MVar a -> a -> IO ()
base Control.Concurrent.MVar
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: * putMVar is single-wakeup. That is, if there are multiple threads blocked in putMVar, and the MVar becomes empty, only one thread will be woken up. The runtime guarantees that the woken thread completes its putMVar operation. * 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 using MVars.
tryPutMVar :: MVar a -> a -> IO Bool
base Control.Concurrent.MVar
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.
isEmptyTMVar :: TMVar a -> STM Bool
stm Control.Concurrent.STM.TMVar
Check whether a given TMVar is empty.
newEmptyTMVar :: STM (TMVar a)
stm Control.Concurrent.STM.TMVar
Create a TMVar which is initially empty.
newEmptyTMVarIO :: IO (TMVar a)
stm Control.Concurrent.STM.TMVar
IO version of newEmptyTMVar. This is useful for creating top-level TMVars using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.
newTMVar :: a -> STM (TMVar a)
stm Control.Concurrent.STM.TMVar
Create a TMVar which contains the supplied value.
newTMVarIO :: a -> IO (TMVar a)
stm Control.Concurrent.STM.TMVar
IO version of newTMVar. This is useful for creating top-level TMVars using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.
putTMVar :: TMVar a -> a -> STM ()
stm Control.Concurrent.STM.TMVar
Put a value into a TMVar. If the TMVar is currently full, putTMVar will retry.
readTMVar :: TMVar a -> STM a
stm Control.Concurrent.STM.TMVar
This is a combination of takeTMVar and putTMVar; ie. it takes the value from the TMVar, puts it back, and also returns it.
swapTMVar :: TMVar a -> a -> STM a
stm Control.Concurrent.STM.TMVar
Swap the contents of a TMVar for a new value.
takeTMVar :: TMVar a -> STM a
stm Control.Concurrent.STM.TMVar
Return the contents of the TMVar. If the TMVar is currently empty, the transaction will retry. After a takeTMVar, the TMVar is left empty.
tryPutTMVar :: TMVar a -> a -> STM Bool
stm Control.Concurrent.STM.TMVar
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.
tryReadTMVar :: TMVar a -> STM (Maybe a)
stm Control.Concurrent.STM.TMVar
A version of readTMVar which does not retry. Instead it returns Nothing if no value is available.
tryTakeTMVar :: TMVar a -> STM (Maybe a)
stm Control.Concurrent.STM.TMVar
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.