Portability | non-portable (requires STM) |
---|---|

Stability | experimental |

Maintainer | Peter Robinson <robinson@ecs.tuwien.ac.at> |

TMVar: Transactional MVars, for use in the AdvAdvSTM monad

Corresponds to Control.Concurrent.STM.TMVar

- data TMVar a
- newTMVar :: MonadAdvSTM m => a -> m (TMVar a)
- newEmptyTMVar :: MonadAdvSTM m => m (TMVar a)
- newTMVarIO :: a -> IO (TMVar a)
- newEmptyTMVarIO :: IO (TMVar a)
- takeTMVar :: MonadAdvSTM m => TMVar a -> m a
- putTMVar :: MonadAdvSTM m => TMVar a -> a -> m ()
- readTMVar :: MonadAdvSTM m => TMVar a -> m a
- swapTMVar :: MonadAdvSTM m => TMVar a -> a -> m a
- tryTakeTMVar :: MonadAdvSTM m => TMVar a -> m (Maybe a)
- tryPutTMVar :: MonadAdvSTM m => TMVar a -> a -> m Bool
- isEmptyTMVar :: MonadAdvSTM m => TMVar a -> m Bool

# TVars

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

newEmptyTMVarIO :: IO (TMVar a)Source

`IO`

version of `newEmptyTMVar`

. This is useful for creating top-level
`TMVar`

s using `System.IO.Unsafe.unsafePerformIO`

, because using
`atomically`

inside `System.IO.Unsafe.unsafePerformIO`

isn't
possible.

takeTMVar :: MonadAdvSTM m => TMVar a -> m aSource

putTMVar :: MonadAdvSTM m => TMVar a -> a -> m ()Source

readTMVar :: MonadAdvSTM m => TMVar a -> m aSource

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

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

if
the `Just`

a`TMVar`

was full with contents `a`

. After `tryTakeTMVar`

, the
`TMVar`

is left empty.

tryPutTMVar :: MonadAdvSTM m => TMVar a -> a -> m BoolSource

isEmptyTMVar :: MonadAdvSTM m => TMVar a -> m BoolSource

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.