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 |
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 ()
- stateTVar :: TVar s -> (s -> (a, s)) -> STM a
- swapTVar :: TVar a -> a -> STM a
- registerDelay :: Int -> IO (TVar Bool)
- mkWeakTVar :: TVar a -> IO () -> IO (Weak (TVar a))
TVars
Shared memory locations that support atomic memory transactions.
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.
readTVarIO :: TVar a -> IO a #
modifyTVar :: TVar a -> (a -> a) -> STM () Source #
Mutate the contents of a TVar
. N.B., this version is
non-strict.
Since: 2.3
modifyTVar' :: TVar a -> (a -> a) -> STM () Source #
Strict version of modifyTVar
.
Since: 2.3
stateTVar :: TVar s -> (s -> (a, s)) -> STM a Source #
Like modifyTVar'
but the function is a simple state transition that can
return a side value which is passed on as the result of the STM
.
Since: 2.5.0
registerDelay :: Int -> IO (TVar Bool) #
Switch the value of returned TVar
from initial value False
to True
after a given number of microseconds. The caveats associated with
threadDelay
also apply.
Be careful not to exceed maxBound :: Int
, which on 32-bit machines is only
2147483647 μs, less than 36 minutes.