Safe HaskellSafe-Inferred



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.


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.





Instances details
MonadIO HIO Source # 
Instance details

Defined in HIO


liftIO :: IO a -> HIO a Source #

Applicative HIO Source # 
Instance details

Defined in HIO


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 #

Functor HIO Source # 
Instance details

Defined in HIO


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

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

Monad HIO Source # 
Instance details

Defined in HIO


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

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

return :: a -> HIO a Source #

HasFork HIO Source # 
Instance details

Defined in HIO


fork :: HIO () -> HIO ThreadId

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 #


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.


Open [Entry] 

Profiling HIO