orc-1.2.1.4: Orchestration-style co-ordination EDSL

Copyright(c) 2008-2010 Galois, Inc.
LicenseBSD3
MaintainerJohn Launchbury <john@galois.com>
StabilityPortability : concurrency, unsafeIntereaveIO
Safe HaskellNone
LanguageHaskell2010

Control.Concurrent.Hierarchical

Description

Hierarchical concurrent threads, which kill all of their descendants when they are killed.

Synopsis

Documentation

data HIO a Source

The HIO monad is simply the IO monad augmented with an environment that tracks the current thread Group. This permits us to keep track of forked threads and kill them en mass when an ancestor is killed. The HIO monad is an instance of MonadIO, so arbitrary IO actions may be embedded in it; however, the user is advised that any action may be summarily killed, and thus it is of extra importance that appropriate bracketing functions are used.

Instances

Monad HIO 
Functor HIO 
Applicative HIO 
HasFork HIO 
MonadIO HIO

The thread-registry environment is a hierarchical structure of local thread neighborhoods.

runHIO :: HIO b -> IO () Source

Runs a HIO operation inside a new thread group that has no parent, and blocks until all subthreads of the operation are done executing. If countingThreads is True, it then prints some debugging information about the threads run (XXX: this seems suboptimal.)

newPrimGroup :: IO Group Source

Creates a new, empty thread group.

newGroup :: HIO Group Source

Creates a new thread group and registers the current environment's thread group in it. If the current group is closed, immediately terminates execution of the current thread.

local :: Group -> HIO a -> HIO a Source

Explicitly sets the current Group environment for a HIO monad.

close :: Group -> HIO () Source

Kill all threads which are descendants of a Group and closes the group, disallowing new threads or groups to be added to the group. Doesn't do anything if the group is already closed.

type Group = (TVar Int, TVar Inhabitants) Source

A thread Group keeps tracks of its inhabitants, which may be threads or other Groups.

finished :: Group -> HIO () Source

Blocks until the Group w is finished executing.