atomic-modify-0.1.0.1: A typeclass for mutable references that have an atomic modify operation.

Control.Concurrent.AtomicModify

Description

Provides AtomicModify, a typeclass for mutable references that have an atomic modify operations. This generalizes atomic modify operations in IO and STM contexts for IORef, MVar, TVar, and TMVar.

• IORef and MVar can be modified in IO.
• TVar and TMVar can be modified in IO or STM.

Synopsis

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

Minimal complete definition

Methods

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

 Source # MethodsatomicModifyStrict :: TVar a -> (a -> (a, b)) -> IO b Source #atomicModifyLazy :: TVar a -> (a -> (a, b)) -> IO b Source # Source # MethodsatomicModifyStrict :: TVar a -> (a -> (a, b)) -> STM b Source #atomicModifyLazy :: TVar a -> (a -> (a, b)) -> STM b Source # Source # MethodsatomicModifyStrict :: IORef a -> (a -> (a, b)) -> IO b Source #atomicModifyLazy :: IORef a -> (a -> (a, b)) -> IO b Source # Source # MethodsatomicModifyStrict :: MVar a -> (a -> (a, b)) -> IO b Source #atomicModifyLazy :: MVar a -> (a -> (a, b)) -> IO b Source # Source # MethodsatomicModifyStrict :: TMVar a -> (a -> (a, b)) -> IO b Source #atomicModifyLazy :: TMVar a -> (a -> (a, b)) -> IO b Source # Source # MethodsatomicModifyStrict :: TMVar a -> (a -> (a, b)) -> STM b Source #atomicModifyLazy :: TMVar a -> (a -> (a, b)) -> STM b Source #

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.