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

Control.Concurrent.CHP.Enroll

Description

A module with support for things that are enrollable (barriers and broadcast channels).

Synopsis

Documentation

data Enrolled b a Source

An enrolled wrapper for barriers that shows at the type-level whether you are enrolled on a barrier. Enrolled Barriers should never be passed to two (or more) processes running in parallel; if two processes synchronise based on a single enroll call, undefined behaviour will result.

class Enrollable b z whereSource

Methods

enroll :: b z -> (Enrolled b z -> CHP a) -> CHP aSource

Enrolls on the given barrier, then executes the given function (passing it in the enrolled barrier) and when that function body finishes, resigns from the barrier and returns the result. If a poison or IO exception is thrown in the inside block, the barrier will be correctly resigned from, and the exception rethrown.

Do not attempt to return the enrolled barrier out of the inner function and use it afterwards.

resign :: Enrolled b z -> CHP a -> CHP aSource

Resigns from a barrier, then executes the given action, and when the action finishes, re-enrolls on the barrier and continues. This function is designed for use from inside the body of the enroll function, to temporarily resign from a barrier, do some things, then re-enroll. Do not use the enrolled barrier inside the resign block. However, you may enroll on the barrier inside this, nesting enroll and resign blocks as much as you like

furtherEnroll :: Enrollable b z => Enrolled b z -> (Enrolled b z -> CHP a) -> CHP aSource

Just like enroll, but starts with an already enrolled item. During the body, you are enrolled twice -- once from the original enrolled item (which is still valid in the body) and once from the new enrolled item passed to the inner function. Afterwards, you are enrolled once, on the original item you had.

This function was added in version 1.3.2.

enrollPair :: (Enrollable b p, Enrollable b' p') => (b p, b' p') -> ((Enrolled b p, Enrolled b' p') -> CHP a) -> CHP aSource

Like enroll but enrolls on the given pair of barriers

enrollList :: Enrollable b p => [b p] -> ([Enrolled b p] -> CHP a) -> CHP aSource

Like enroll but enrolls on the given list of barriers

enrollAll :: Enrollable b p => CHP (b p) -> [Enrolled b p -> CHP a] -> CHP [a]Source

Given a command to allocate a new barrier, and a list of processes that use that barrier, enrolls the appropriate number of times (i.e. the list length) and runs all the processes in parallel using that barrier, then returns a list of the results.

If you have already allocated the barrier, pass return bar as the first parameter.

Added in version 1.7.0.

enrollAll_ :: Enrollable b p => CHP (b p) -> [Enrolled b p -> CHP a] -> CHP ()Source

Like enrollAll, but discards the results.

Added in version 1.7.0.

enrollAllT :: Enrollable b p => ([a] -> CHP c) -> CHP (b p) -> [Enrolled b p -> a] -> CHP cSource

enrollOneMany :: Enrollable b p => ([Enrolled b p] -> CHP a) -> [(CHP (b p), Enrolled b p -> CHP c)] -> CHP (a, [c])Source