| Portability | non-portable (STM, CPP) |
|---|---|
| Stability | experimental |
| Maintainer | wren@community.haskell.org |
Control.Concurrent.STM.TVar.Compat
Description
Compatibility layer for older versions of the stm library.
Namely, we define readTVarIO which stm-2.1.1 lacks; and we
define modifyTVar, modifyTVar', and swapTVar which stm-X.X.X
lacks. This module uses Cabal-style CPP macros in order to use
the package versions when available.
- 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)
The TVar type
data TVar a
Shared memory locations that support atomic memory transactions.
Creating TVars
IO version of newTVar. This is useful for creating top-level
TVars using System.IO.Unsafe.unsafePerformIO, because using
atomically inside System.IO.Unsafe.unsafePerformIO isn't
possible.
Reading from TVars
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.
Writing to TVars
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.
Other capabilities
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.