aivika-experiment-4.0.3: Simulation experiments for the Aivika library

CopyrightCopyright (c) 2012-2015, David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell98

Simulation.Aivika.Experiment.MRef

Description

Tested with: GHC 7.10.1

The module defines a shared mutable reference accessible from different threads.

Synopsis

Documentation

data MRef a Source

This is a shared mutable reference accessible from different threads.

newMRef :: a -> IO (MRef a) Source

Create a new shared reference with the specified initial value.

readMRef :: MRef a -> IO a Source

Read the contents of the shared reference.

maybeReadMRef :: b -> (a -> IO b) -> MRef (Maybe a) -> IO b Source

Like maybe but for the shared reference under assumption that the reference is updated only once by its initial value.

writeMRef :: MRef a -> a -> IO () Source

Update the contents of the shared reference.

maybeWriteMRef :: MRef (Maybe a) -> IO a -> (a -> IO b) -> IO b Source

Update the contents if the reference was empty and then return a result of applying the specified function to either the initial or current value.

modifyMRef_ :: MRef a -> (a -> IO a) -> IO () Source

Modify the contents of the shared reference.

modifyMRef :: MRef a -> (a -> IO (a, b)) -> IO b Source

Modify the contents of the shared reference but allow returning the result.

withMRef :: MRef a -> (a -> IO b) -> IO b Source

A safe wrapper for operating with the contents of shared reference.