monad-par-0.3.4.7: A library for parallel programming based on a monad

Safe Haskell | None
Language | Haskell98

Control.Monad.Par.Scheds.TraceInternal

Description

This module exposes the internals of the `Par` monad so that you can build your own scheduler or other extensions. Do not use this module for purposes other than extending the `Par` monad with new functionality.

Synopsis

- data Trace
  - = forall a . Get (IVar a) (a -> Trace)
  - | forall a . Put (IVar a) a Trace
  - | forall a . New (IVarContents a) (IVar a -> Trace)
  - | Fork Trace Trace
  - | Done
  - | Yield Trace
  - | forall a . LiftIO (IO a) (a -> Trace)
- data Sched = Sched {
  - no :: !Int
  - workpool :: IORef [Trace]
  - idle :: IORef [MVar Bool]
  - scheds :: [Sched]
  }
- newtype Par a = Par {
  - runCont :: (a -> Trace) -> Trace
  }
- newtype IVar a = IVar (IORef (IVarContents a))
- data IVarContents a
  - = Full a
  - | Empty
  - | Blocked [a -> Trace]
- sched :: Bool -> Sched -> Trace -> IO ()
- runPar :: Par a -> a
- runParIO :: Par a -> IO a
- runParAsync :: Par a -> a
- new :: Par (IVar a)
- newFull :: NFData a => a -> Par (IVar a)
- newFull_ :: a -> Par (IVar a)
- get :: IVar a -> Par a
- put_ :: IVar a -> a -> Par ()
- put :: NFData a => IVar a -> a -> Par ()
- pollIVar :: IVar a -> IO (Maybe a)
- yield :: Par ()

# Documentation

data Trace Source

Constructors

forall a . Get (IVar a) (a -> Trace) |
forall a . Put (IVar a) a Trace |
forall a . New (IVarContents a) (IVar a -> Trace) |
Fork Trace Trace |
Done |
Yield Trace |
forall a . LiftIO (IO a) (a -> Trace) |

data Sched Source

Constructors

Sched |

Fields

no :: !Int
workpool :: IORef [Trace]
idle :: IORef [MVar Bool]
scheds :: [Sched]

newtype Par a Source

Constructors

Par |

Fields

runCont :: (a -> Trace) -> Trace

Instances

Monad Par Source |
Functor Par Source |
Applicative Par Source |

newtype IVar a Source

Constructors

IVar (IORef (IVarContents a)) |

Instances

ParFuture IVar ParIO |
ParIVar IVar ParIO |
Eq (IVar a) Source | Equality for IVars is physical equality, as with other reference types.
NFData (IVar a) Source |

data IVarContents a Source

Constructors

Full a |
Empty |
Blocked [a -> Trace] |

sched :: Bool -> Sched -> Trace -> IO () Source

The main scheduler loop.

runPar :: Par a -> a Source

runParIO :: Par a -> IO a Source

A version that avoids an internal `unsafePerformIO` for calling contexts that are already in the `IO` monad.

runParAsync :: Par a -> a Source

An asynchronous version in which the main thread of control in a Par computation can return while forked computations still run in the background.

new :: Par (IVar a) Source

creates a new `IVar`

newFull :: NFData a => a -> Par (IVar a) Source

creates a new `IVar` that contains a value

newFull_ :: a -> Par (IVar a) Source

creates a new `IVar` that contains a value (head-strict only)

get :: IVar a -> Par a Source

read the value in a `IVar`. The `get` can only return when the value has been written by a prior or parallel `put` to the same `IVar`.

put_ :: IVar a -> a -> Par () Source

like `put`, but only head-strict rather than fully-strict.

put :: NFData a => IVar a -> a -> Par () Source

put a value into a `IVar`. Multiple `put`s to the same `IVar` are not allowed, and result in a runtime error.

`put` fully evaluates its argument, which therefore must be an instance of `NFData`. The idea is that this forces the work to happen when we expect it, rather than being passed to the consumer of the `IVar` and performed later, which often results in less parallelism than expected.

Sometimes partial strictness is more appropriate: see `put_`.

pollIVar :: IVar a -> IO (Maybe a) Source

yield :: Par () Source

Allows other parallel computations to progress. (should not be necessary in most cases).