-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Fork threads and wait for their result -- -- This package provides functions to fork threads and wait for their -- termination. The result of a thread can also be retrieved, whether -- it's an exception or a normal value. -- -- Besides waiting for the termination of a single thread this packages -- also provides functions to wait for a group of threads to terminate. -- -- This package is similar to the threadmanager and -- async packages. The advantages of this package are: -- -- @package threads @version 0.2 -- | Standard threads extended with the ability to wait for their -- termination. -- -- 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 ( ... )
--   
module Control.Concurrent.Thread -- | A Result α is an abstract type representing the result -- of a thread that is executing or has executed a computation of type -- IO α. data Result α -- | Sparks off a new thread to run the given IO computation and -- returns the ThreadId of the newly created thread paired with -- the Result of the thread which can be waited -- upon. -- -- The new thread will be a lightweight thread; if you want to use a -- foreign library that uses thread-local storage, use forkOS -- instead. -- -- GHC note: the new thread inherits the blocked state of the parent (see -- block). forkIO :: IO α -> IO (ThreadId, Result α) -- | Like forkIO, this sparks off a new thread to run the given -- IO computation and returns the ThreadId of the newly -- created thread paired with the Result of the thread which can -- be waited upon. -- -- Unlike forkIO, forkOS creates a bound thread, -- which is necessary if you need to call foreign (non-Haskell) libraries -- that make use of thread-local state, such as OpenGL (see -- Control.Concurrent). -- -- Using forkOS instead of forkIO makes no difference at -- all to the scheduling behaviour of the Haskell runtime system. It is a -- common misconception that you need to use forkOS instead of -- forkIO to avoid blocking all the Haskell threads when making a -- foreign call; this isn't the case. To allow foreign calls to be made -- without blocking all the Haskell threads (with GHC), it is only -- necessary to use the -threaded option when linking your -- program, and to make sure the foreign import is not marked -- unsafe. forkOS :: IO α -> IO (ThreadId, Result α) -- | Like forkIO, but lets you specify on which CPU the thread is -- created. Unlike a forkIO thread, a thread created by -- forkOnIO will stay on the same CPU for its entire lifetime -- (forkIO threads can migrate between CPUs according to the -- scheduling policy). forkOnIO is useful for overriding the -- scheduling policy when you know in advance how best to distribute the -- threads. -- -- The Int argument specifies the CPU number; it is interpreted -- modulo numCapabilities (note that it actually specifies a -- capability number rather than a CPU number, but to a first -- approximation the two are equivalent). forkOnIO :: Int -> IO α -> IO (ThreadId, Result α) -- | Block until the thread, to which the given Result belongs, is -- terminated. -- -- wait :: Result α -> IO (Either SomeException α) -- | Like wait but will ignore the value returned by the thread. wait_ :: Result α -> IO () -- | Like wait but will either rethrow the exception that was thrown -- in the thread or return the value that was returned by the thread. unsafeWait :: Result α -> IO α -- | Like unsafeWait in that it will rethrow the exception that was -- thrown in the thread but it will ignore the value returned by the -- thread. unsafeWait_ :: Result α -> IO () -- | A non-blocking wait. -- -- -- -- Notice that this observation is only a snapshot of a thread's state. -- By the time a program reacts on its result it may already be out of -- date. status :: Result α -> IO (Maybe (Either SomeException α)) -- | If the thread, to which the given Result belongs, is currently -- running return True and return False otherwise. -- -- Notice that this observation is only a snapshot of a thread's state. -- By the time a program reacts on its result it may already be out of -- date. isRunning :: Result α -> IO Bool -- | 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 ( ... )
--   
module Control.Concurrent.Thread.Group -- | 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: -- -- data ThreadGroup -- | Create an empty group of threads. new :: IO ThreadGroup -- | Same as Control.Concurrent.Thread.forkIO but -- additionaly adds the thread to the group. forkIO :: ThreadGroup -> IO α -> IO (ThreadId, Result α) -- | Same as Control.Concurrent.Thread.forkOS but -- additionaly adds the thread to the group. forkOS :: ThreadGroup -> IO α -> IO (ThreadId, Result α) -- | Same as Control.Concurrent.Thread.forkOnIO but -- additionaly adds the thread to the group. (GHC only) forkOnIO :: Int -> ThreadGroup -> IO α -> IO (ThreadId, Result α) -- | Block until all threads, that were added to the group have terminated. wait :: ThreadGroup -> IO () -- | 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. isAnyRunning :: ThreadGroup -> IO Bool instance Typeable ThreadGroup