chp-2.2.0: An implementation of concurrency ideas from Communicating Sequential Processes

Control.Concurrent.CHP.Parallel

Synopsis

Documentation

runParallel :: [CHP a] -> CHP [a]Source

This type-class supports parallel composition of processes. You may use the runParallel function to run a list of processes, or the <||> operator to run just a pair of processes.

In each case, the composition waits for all processes to finish, either successfully or with poison. At the end of this, if any process exited with poison, the composition will "rethrow" this poison. If all the processes completed successfully, the results will be returned. If you want to ignore poison from the sub-processes, use an empty poison handler and onPoisonTrap with each branch.

Runs the given list of processes in parallel, and then returns a list of the results, in the same order as the processes given. Will only return when all the inner processes have completed.

In version 1.5.0, a bug was introduced such that runParallel [] would deadlock; this was fixed in version 1.5.1.

runParallel_ :: [CHP a] -> CHP ()Source

Runs all the given processes in parallel and discards any output. Does not return until all the processes have completed. runParallel_ ps is effectively equivalent to runParallel ps >> return ().

In version 1.5.0, a bug was introduced such that runParallel_ [] would deadlock; this was fixed in version 1.5.1.

(<||>) :: CHP a -> CHP b -> CHP (a, b)Source

A useful operator for performing a two process equivalent of runParallel that gives the return values back as a pair rather than a list. This also allows the values to have different types

(<|*|>) :: CHP a -> CHP b -> CHP ()Source

An operator similar to <||> that discards the output (more like an operator version of runParallel_).

Added in version 1.1.0.

runParMapM :: (a -> CHP b) -> [a] -> CHP [b]Source

A shorthand for applying mapM in parallel; really the composition of runParallel and map.

Added in version 1.5.0.

runParMapM_ :: (a -> CHP b) -> [a] -> CHP ()Source

A shorthand for applying mapM_ in parallel; really the composition of runParallel_ and map.

Added in version 1.5.0.

data ForkingT m a Source

A monad transformer used for introducing forking blocks.

Instances

liftForking :: Monad m => m a -> ForkingT m aSource

An implementation of lift for the ForkingT monad transformer.

Added in version 2.2.0.

forking :: MonadCHP m => ForkingT m a -> m aSource

Executes a forking block. Processes may be forked off inside (using the fork function). When the block completes, it waits for all the forked off processes to complete before returning the output, as long as none of the processes terminated with uncaught poison. If they did, the poison is propagated (rethrown).

fork :: MonadCHP m => CHP () -> ForkingT m ()Source

Forks off the given process. The process then runs in parallel with this code, until the end of the forking block, when all forked-off processes are waited for. At that point, once all of the processes have finished, if any of them threw poison it is propagated.