HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulethreads-0.5.1.8Haskell2010

Control.Concurrent.Thread

Standard threads extended with the ability to wait for their return value.

This module exports equivalently named functions from Control.Concurrent (and GHC.Conc). Avoid ambiguities by importing this module qualified. May we suggest:

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

The following is an example how to use this module:


import qualified Control.Concurrent.Thread as Thread ( forkIO, result )

main = do (tid, wait) <- Thread.forkIO $ do x <- someExpensiveComputation
                                           return x
         doSomethingElse
         x <- Thread.result =<< wait
         doSomethingWithResult x
  • 1 type
  • 6 values
  • Packagethreads-0.5.1.8
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceThread.hs

Forking threads

5 declarations
valueforkIO :: IO a -> IO (ThreadId, IO (Result a))
#

Like Control.Concurrent.forkIO but returns a computation that when executed blocks until the thread terminates then returns the final value of the thread.

valueforkOS :: IO a -> IO (ThreadId, IO (Result a))
#

Like Control.Concurrent.forkOS but returns a computation that when executed blocks until the thread terminates then returns the final value of the thread.

valueforkOn :: Int -> IO a -> IO (ThreadId, IO (Result a))
#

Like Control.Concurrent.forkOn but returns a computation that when executed blocks until the thread terminates then returns the final value of the thread.

Results

2 declarations
typetype Result a = Either SomeException a
#

A result of a thread is either some exception that was thrown in the thread and wasn't catched or the actual value that was returned by the thread.