Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- class AtomicModify ref m where
- atomicModifyStrict :: ref a -> (a -> (a, b)) -> m b
- atomicModifyLazy :: ref a -> (a -> (a, b)) -> m b
- atomicModifyStrict_ :: AtomicModify v m => v a -> (a -> a) -> m ()
- atomicModifyLazy_ :: AtomicModify v m => v a -> (a -> a) -> m ()
Documentation
class AtomicModify ref m where Source #
A typeclass for mutable references that have an atomic modify operation.
Type variables:
ref
- The reference (e.g.IORef
,TVar
,MVar
,TMVar
)m
- The monad in which the modification takes place (e.g.IO
,STM
)
As the name "atomic" implies, these functions are useful for using mutable references in a safe way to prevent race conditions in a multithreaded program.
atomicModifyStrict :: ref a -> (a -> (a, b)) -> m b Source #
Atomically modify the contents of a ref
(type a
) and produce a value (type
b
). This is strict; it forces the value stored in the ref
as well as the
value returned.
atomicModifyLazy :: ref a -> (a -> (a, b)) -> m b Source #
Atomically modify the contents of a ref
(type a
) and produce a value (type
b
). This is lazy, which means if the program calls atomicModifyLazy
many
times, but seldomly uses the value, thunks will pile up in memory resulting in
a space leak.
Instances
atomicModifyStrict_ :: AtomicModify v m => v a -> (a -> a) -> m () Source #
Atomically modify the contents of a ref
. This is strict; it forces the value
stored in the ref
as well as the value returned.
atomicModifyLazy_ :: AtomicModify v m => v a -> (a -> a) -> m () Source #
Atomically modify the contents of a ref
(type a
) and produce a value (type
b
). This is lazy, which means if the program calls atomicModifyLazy_
many
times, but seldomly uses the value, thunks will pile up in memory resulting in a
space leak.