lifted-threads-1.0: lifted IO operations from the threads library

Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Concurrent.Thread.Group.Lifted

Contents

Description

This is a wrapped version of Control.Concurrent.Thread.Group with types generalised from IO to all monads in either MonadBase or MonadBaseControl.

Synopsis

Documentation

data ThreadGroup :: *

A ThreadGroup can be understood as a counter which counts the number of threads that were added to the group minus the ones that have terminated.

More formally a ThreadGroup has the following semantics:

  • new initializes the counter to 0.
  • Forking a thread increments the counter.
  • When a forked thread terminates, whether normally or by raising an exception, the counter is decremented.
  • nrOfRunning yields a transaction that returns the counter.
  • wait blocks as long as the counter is greater than 0.
  • waitN blocks as long as the counter is greater or equal to the specified number.

new :: MonadBase IO m => m ThreadGroup Source

Generalized version of new.

nrOfRunning :: ThreadGroup -> STM Int

Yield a transaction that returns the number of running threads in the group.

Note that because this function yields a STM computation, the returned number is guaranteed to be consistent inside the transaction.

wait :: MonadBase IO m => ThreadGroup -> m () Source

Generalized version of wait.

waitN :: MonadBase IO m => Int -> ThreadGroup -> m () Source

Generalized version of waitN.

Forking threads

fork :: MonadBaseControl IO m => ThreadGroup -> m a -> m (ThreadId, m (Result a)) Source

Generalized version of forkIO.

forkOS :: MonadBaseControl IO m => ThreadGroup -> m a -> m (ThreadId, m (Result a)) Source

Generalized version of forkOS.

forkOn :: MonadBaseControl IO m => Int -> ThreadGroup -> m a -> m (ThreadId, m (Result a)) Source

Generalized version of forkOn.

forkWithUnmask :: MonadBaseControl IO m => ThreadGroup -> ((forall b. m b -> m b) -> m a) -> m (ThreadId, m (Result a)) Source

Generalized version of forkIOWithUnmask.

forkOnWithUnmask :: MonadBaseControl IO m => Int -> ThreadGroup -> ((forall b. m b -> m b) -> m a) -> m (ThreadId, m (Result a)) Source

Generalized version of forkOnWithUnmask.