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

Stabilityexperimental
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Safe HaskellSafe-Inferred

Simulation.Aivika.Experiment.MRef

Description

Tested with: GHC 7.8.3

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 aSource

Read the contents of the shared reference.

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

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 bSource

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 bSource

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

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

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