Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> , Roel van Dijk <vandijk.roel@gmail.com> |
---|---|
Safe Haskell | Trustworthy |
This module extends Control.Concurrent.Thread
with the ability to wait for
a group of threads to terminate.
This module exports equivalently named functions from Control.Concurrent
,
(GHC.Conc
), and Control.Concurrent.Thread
. Avoid ambiguities by importing
this module qualified. May we suggest:
import Control.Concurrent.Thread.Group ( ThreadGroup ) import qualified Control.Concurrent.Thread.Group as ThreadGroup ( ... )
- data ThreadGroup
- new :: IO ThreadGroup
- nrOfRunning :: ThreadGroup -> STM Int
- wait :: ThreadGroup -> IO ()
- forkIO :: ThreadGroup -> IO α -> IO (ThreadId, IO (Result α))
- forkOS :: ThreadGroup -> IO α -> IO (ThreadId, IO (Result α))
- forkOn :: Int -> ThreadGroup -> IO α -> IO (ThreadId, IO (Result α))
- forkIOWithUnmask :: ThreadGroup -> ((forall β. IO β -> IO β) -> IO α) -> IO (ThreadId, IO (Result α))
- forkOnWithUnmask :: Int -> ThreadGroup -> ((forall β. IO β -> IO β) -> IO α) -> IO (ThreadId, IO (Result α))
Documentation
data ThreadGroup Source
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 not 0.
Create an empty group of threads.
nrOfRunning :: ThreadGroup -> STM IntSource
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 :: ThreadGroup -> IO ()Source
Convenience function which blocks until all threads, that were added to the group have terminated.
Forking threads
forkIO :: ThreadGroup -> IO α -> IO (ThreadId, IO (Result α))Source
Same as Control.Concurrent.Thread.
but additionaly adds
the thread to the group.
forkIO
forkOS :: ThreadGroup -> IO α -> IO (ThreadId, IO (Result α))Source
Same as Control.Concurrent.Thread.
but additionaly adds
the thread to the group.
forkOS
forkOn :: Int -> ThreadGroup -> IO α -> IO (ThreadId, IO (Result α))Source
Same as Control.Concurrent.Thread.
but
additionaly adds the thread to the group.
forkOn
forkIOWithUnmask :: ThreadGroup -> ((forall β. IO β -> IO β) -> IO α) -> IO (ThreadId, IO (Result α))Source
Same as Control.Concurrent.Thread.
but
additionaly adds the thread to the group.
forkIOWithUnmask
forkOnWithUnmask :: Int -> ThreadGroup -> ((forall β. IO β -> IO β) -> IO α) -> IO (ThreadId, IO (Result α))Source
Like Control.Concurrent.Thread.
but
additionaly adds the thread to the group.
forkOnWithUnmask