stm-2.4.4.1: Software Transactional Memory

Copyright | (c) The University of Glasgow 2004
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | experimental
Portability | non-portable (requires STM)
Safe Haskell | Trustworthy
Language | Haskell2010

Control.Concurrent.STM.TVar

Contents

- TVars

Description

TVar: Transactional variables

Synopsis

- data TVar a :: * -> *
- newTVar :: a -> STM (TVar a)
- newTVarIO :: a -> IO (TVar a)
- readTVar :: TVar a -> STM a
- readTVarIO :: TVar a -> IO a
- writeTVar :: TVar a -> a -> STM ()
- modifyTVar :: TVar a -> (a -> a) -> STM ()
- modifyTVar' :: TVar a -> (a -> a) -> STM ()
- swapTVar :: TVar a -> a -> STM a
- registerDelay :: Int -> IO (TVar Bool)
- mkWeakTVar :: TVar a -> IO () -> IO (Weak (TVar a))

# TVars

data TVar a :: * -> * #

Shared memory locations that support atomic memory transactions.

Instances

Eq (TVar a) |
Methods (==) :: TVar a -> TVar a -> Bool # (/=) :: TVar a -> TVar a -> Bool #

newTVar :: a -> STM (TVar a) #

Create a new TVar holding a value supplied

newTVarIO :: a -> IO (TVar a) #

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

readTVar :: TVar a -> STM a #

Return the current value stored in a TVar

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`.

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

Write the supplied value into a TVar

modifyTVar :: TVar a -> (a -> a) -> STM () Source #

Mutate the contents of a `TVar`. N.B., this version is non-strict.

modifyTVar' :: TVar a -> (a -> a) -> STM () Source #

Strict version of `modifyTVar`.

swapTVar :: TVar a -> a -> STM a Source #

Swap the contents of a `TVar` for a new value.

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.

mkWeakTVar :: TVar a -> IO () -> IO (Weak (TVar a)) Source #

Make a `Weak` pointer to a `TVar`, using the second argument as a finalizer to run when `TVar` is garbage-collected

Since: 2.4.3