Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This is a wrapped version of Control.Concurrent.Thread.Group
with types generalised from IO
to all monads in either MonadBase
or MonadBaseControl
.
- data ThreadGroup :: *
- new :: MonadBase IO m => m ThreadGroup
- nrOfRunning :: ThreadGroup -> STM Int
- wait :: MonadBase IO m => ThreadGroup -> m ()
- waitN :: MonadBase IO m => Int -> ThreadGroup -> m ()
- fork :: MonadBaseControl IO m => ThreadGroup -> m a -> m (ThreadId, m (Result a))
- forkOS :: MonadBaseControl IO m => ThreadGroup -> m a -> m (ThreadId, m (Result a))
- forkOn :: MonadBaseControl IO m => Int -> ThreadGroup -> m a -> m (ThreadId, m (Result a))
- forkWithUnmask :: MonadBaseControl IO m => ThreadGroup -> ((forall b. m b -> m b) -> m a) -> m (ThreadId, m (Result a))
- forkOnWithUnmask :: MonadBaseControl IO m => Int -> ThreadGroup -> ((forall b. m b -> m b) -> m a) -> m (ThreadId, m (Result a))
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.
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.
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
.