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

Safe HaskellSafe
LanguageHaskell2010

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.

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

atomicModifyStrict, atomicModifyLazy

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

AtomicModify TVar IO Source # 

Methods

atomicModifyStrict :: TVar a -> (a -> (a, b)) -> IO b Source #

atomicModifyLazy :: TVar a -> (a -> (a, b)) -> IO b Source #

AtomicModify TVar STM Source # 

Methods

atomicModifyStrict :: TVar a -> (a -> (a, b)) -> STM b Source #

atomicModifyLazy :: TVar a -> (a -> (a, b)) -> STM b Source #

AtomicModify IORef IO Source # 

Methods

atomicModifyStrict :: IORef a -> (a -> (a, b)) -> IO b Source #

atomicModifyLazy :: IORef a -> (a -> (a, b)) -> IO b Source #

AtomicModify MVar IO Source # 

Methods

atomicModifyStrict :: MVar a -> (a -> (a, b)) -> IO b Source #

atomicModifyLazy :: MVar a -> (a -> (a, b)) -> IO b Source #

AtomicModify TMVar IO Source # 

Methods

atomicModifyStrict :: TMVar a -> (a -> (a, b)) -> IO b Source #

atomicModifyLazy :: TMVar a -> (a -> (a, b)) -> IO b Source #

AtomicModify TMVar STM Source # 

Methods

atomicModifyStrict :: 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.