threads- Fork threads and wait for their result

MaintainerBas van Dijk <> , Roel van Dijk <>




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 and Control.Concurrent.Thread. Avoid ambiguities by importing one or both qualified. We suggest importing this module like:

 import Control.Concurrent.Thread.Group ( ThreadGroup )
 import qualified Control.Concurrent.Thread.Group as ThreadGroup ( ... )



new :: IO ThreadGroupSource

Create a new empty group.

Forking threads

forkIO :: ThreadGroup -> IO α -> IO (ThreadId α)Source

Same as Control.Concurrent.Thread.forkIO but additionaly adds the thread to the group.

forkOS :: ThreadGroup -> IO α -> IO (ThreadId α)Source

Same as Control.Concurrent.Thread.forkOS but additionaly adds the thread to the group.

Waiting & Status

wait :: ThreadGroup -> IO ()Source

Block until all threads, that were added to the group have terminated.

isAnyRunning :: ThreadGroup -> IO BoolSource

Returns True if any thread in the group is running and returns False otherwise.

Notice that this observation is only a snapshot of a group's state. By the time a program reacts on its result it may already be out of date.