garden
Safe HaskellNone
LanguageHaskell2010

HIO

Description

This is a re-implementation of a module from Galois. It is part of the orc package, which I am interested in experimenting with. I wanted to re-implement 2 out of the 3 modules in the original Orc package, so rather than import it only to chuck 2/3 of it just for its HIO module I have reproduced it here.

Synopsis

Hierarchical IO

newtype HIO a Source #

HIO is simply IO augmented with an environment that tracks the current thread Group. This permits tracking forked threads and culling them en masse when an ancestor is killed. Because of its MonadIO instance arbitrary IO actions may be embedded; however it is advised that any action be summarily killed.

Constructors

HIO 

Fields

Instances

Instances details
Monad HIO Source # 
Instance details

Defined in HIO

Methods

(>>=) :: HIO a -> (a -> HIO b) -> HIO b Source #

(>>) :: HIO a -> HIO b -> HIO b Source #

return :: a -> HIO a Source #

Functor HIO Source # 
Instance details

Defined in HIO

Methods

fmap :: (a -> b) -> HIO a -> HIO b Source #

(<$) :: a -> HIO b -> HIO a Source #

Applicative HIO Source # 
Instance details

Defined in HIO

Methods

pure :: a -> HIO a Source #

(<*>) :: HIO (a -> b) -> HIO a -> HIO b Source #

liftA2 :: (a -> b -> c) -> HIO a -> HIO b -> HIO c Source #

(*>) :: HIO a -> HIO b -> HIO b Source #

(<*) :: HIO a -> HIO b -> HIO a Source #

MonadIO HIO Source # 
Instance details

Defined in HIO

Methods

liftIO :: IO a -> HIO a Source #

HasFork HIO Source # 
Instance details

Defined in HIO

Methods

fork :: HIO () -> HIO ThreadId

MonadIO (CPS () HIO) Source # 
Instance details

Defined in Orc

Methods

liftIO :: IO a -> CPS () HIO a Source #

runHIO :: HIO b -> IO () Source #

Runs a HIO computation 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.

unHIO :: HIO a -> a Source #

Unsafely extracts the underlying result value from the HIO monad.

Thread groups

type Group = (TVar Int, TVar Inhabitants) Source #

A thread Group accounts for its inhabitants, which may be threads or other Groups.

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 -> IO () Source #

Kills 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.

finished :: Group -> HIO () Source #

Blocks until the Group w is finished executing.

register :: Entry -> Group -> IO () Source #

Registers a thread/group entry tid in a Group, terminating the current thread (suicide) if the group is closed.

Auxiliary types

data Entry Source #

Constructors

Thread ThreadId 
Group Group 

data Inhabitants Source #

A group can be Closed, in which case it is empty and cannot accept new inhabitants; or Open, in which case it contains any number of constituents, and new Threads and Groups may be registered with it.

Constructors

Closed 
Open [Entry] 

Profiling HIO