concurrency-1.2.1.2: Typeclasses, functions, and data types for concurrency and STM.

Copyright(c) 2016 Michael Walker
LicenseMIT
MaintainerMichael Walker <mike@barrucadu.co.uk>
Stabilitystable
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Control.Concurrent.Classy.STM.TMVar

Contents

Description

Transactional MVars, for use with MonadSTM.

Deviations: TMVar as defined here does not have an Eq instance, this is because the MonadSTM TVar type does not have an Eq constraint. Furthermore, the newTMVarIO, newEmptyTMVarIO, and mkWeakTMVar functions are not provided.

Synopsis

TMVars

data TMVar stm a Source #

A TMVar is like an MVar or a mVar, but using transactional memory. As transactions are atomic, this makes dealing with multiple TMVars easier than wrangling multiple mVars.

Since: 1.0.0.0

newTMVar :: MonadSTM stm => a -> stm (TMVar stm a) Source #

Create a TMVar containing the given value.

Since: 1.0.0.0

newTMVarN :: MonadSTM stm => String -> a -> stm (TMVar stm a) Source #

Create a TMVar containing the given value, with the given name.

Name conflicts are handled as usual for TVars. The name is prefixed with "ctmvar-".

Since: 1.0.0.0

newEmptyTMVar :: MonadSTM stm => stm (TMVar stm a) Source #

Create a new empty TMVar.

Since: 1.0.0.0

newEmptyTMVarN :: MonadSTM stm => String -> stm (TMVar stm a) Source #

Create a new empty TMVar with the given name.

Name conflicts are handled as usual for TVars. The name is prefixed with "ctmvar-".

Since: 1.0.0.0

takeTMVar :: MonadSTM stm => TMVar stm a -> stm a Source #

Take the contents of a TMVar, or retry if it is empty.

Since: 1.0.0.0

putTMVar :: MonadSTM stm => TMVar stm a -> a -> stm () Source #

Write to a TMVar, or retry if it is full.

Since: 1.0.0.0

readTMVar :: MonadSTM stm => TMVar stm a -> stm a Source #

Read from a TMVar without emptying, or retry if it is empty.

Since: 1.0.0.0

tryTakeTMVar :: MonadSTM stm => TMVar stm a -> stm (Maybe a) Source #

Try to take the contents of a TMVar, returning Nothing if it is empty.

Since: 1.0.0.0

tryPutTMVar :: MonadSTM stm => TMVar stm a -> a -> stm Bool Source #

Try to write to a TMVar, returning False if it is full.

Since: 1.0.0.0

tryReadTMVar :: MonadSTM stm => TMVar stm a -> stm (Maybe a) Source #

Try to read from a TMVar without emptying, returning Nothing if it is empty.

Since: 1.0.0.0

isEmptyTMVar :: MonadSTM stm => TMVar stm a -> stm Bool Source #

Check if a TMVar is empty or not.

Since: 1.0.0.0

swapTMVar :: MonadSTM stm => TMVar stm a -> a -> stm a Source #

Swap the contents of a TMVar returning the old contents, or retry if it is empty.

Since: 1.0.0.0