stm-io-hooks-1.1.0: STM with IO hooks

Copyright(c) Peter Robinson 2009, (c) The University of Glasgow 2004
LicenseBSD3
MaintainerPeter Robinson <robinson@ecs.tuwien.ac.at>
Stabilityexperimental
Portabilitynon-portable (requires STM)
Safe HaskellNone
LanguageHaskell98

Control.Concurrent.AdvSTM.TMVar

Contents

Description

TMVar: Transactional MVars, for use in the AdvAdvSTM monad

Corresponds to Control.Concurrent.STM.TMVar

Synopsis

TVars

data TMVar a Source

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 :: MonadAdvSTM m => a -> m (TMVar a) Source

Create a TMVar which contains the supplied value.

newEmptyTMVar :: MonadAdvSTM m => m (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 TMVars 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 TMVars using unsafePerformIO, because using atomically inside unsafePerformIO isn't possible.

takeTMVar :: MonadAdvSTM m => TMVar a -> m 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 :: MonadAdvSTM m => TMVar a -> a -> m () Source

Put a value into a TMVar. If the TMVar is currently full, putTMVar will retry.

readTMVar :: MonadAdvSTM m => TMVar a -> m 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.

swapTMVar :: MonadAdvSTM m => TMVar a -> a -> m a Source

Swap the contents of a TMVar for a new value.

tryTakeTMVar :: MonadAdvSTM m => TMVar a -> m (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 :: MonadAdvSTM m => TMVar a -> a -> m 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 :: MonadAdvSTM m => TMVar a -> m Bool Source

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.