Control.Concurrent.STM.TVar

stm-2.2.0.1: Software Transactional Memory

Portability | non-portable (requires STM)
Stability | experimental
Maintainer | libraries@haskell.org

Control.Concurrent.STM.TVar

Contents

- TVars

Description

TVar: Transactional variables

Synopsis

- data TVar a
- newTVar :: a -> STM (TVar a)
- readTVar :: TVar a -> STM a
- writeTVar :: TVar a -> a -> STM ()
- newTVarIO :: a -> IO (TVar a)
- readTVarIO :: TVar a -> IO a
- registerDelay :: Int -> IO (TVar Bool)

# TVars

data TVar a

Shared memory locations that support atomic memory transactions.

Instances

Typeable1 TVar |
Eq (TVar a) |

newTVar :: a -> STM (TVar a)

Create a new TVar holding a value supplied

readTVar :: TVar a -> STM a

Return the current value stored in a TVar

writeTVar :: TVar a -> a -> STM ()

Write the supplied value into a TVar

newTVarIO :: a -> IO (TVar a)

`IO` version of `newTVar`. This is useful for creating top-level `TVar`s using `System.IO.Unsafe.unsafePerformIO`, because using `atomically` inside `System.IO.Unsafe.unsafePerformIO` isn't possible.

readTVarIO :: TVar a -> IO a

Return the current value stored in a TVar. This is equivalent to

      readTVarIO = atomically . readTVar

but works much faster, because it doesn't perform a complete transaction, it just reads the current value of the `TVar`.

registerDelay :: Int -> IO (TVar Bool)

Set the value of returned TVar to True after a given number of microseconds. The caveats associated with threadDelay also apply.