fork

Generalized version of forkIO. Note that, while the forked computation m () has access to the captured state, all its side-effects in m are discarded. It is run only for its side-effects in IO.
Fork a thread, acquiring an Async value
fork lifted to any monad with 'MonadBaseControl IO m' capability.
Fork a computation to happen concurrently. Communication may happen over MVars.
Create a child thread to execute an action within a scope. Note: The child thread does not mask asynchronous exceptions, regardless of the parent thread's masking state. To create a child thread with a different initial masking state, use forkWith.
This runs an action parallelly to the starting thread. Since it is an Applicative Functor and not a Monad, there are no data dependencies between the actions and thus all actions in a T can be run parallelly. Only the IO actions are parallelised but not the combining function passed to liftA2 et.al. That is, the main work must be done in the IO actions in order to benefit from parallelisation.
fork runs an IO action in parallel while respecting a maximum number of threads. Evaluating the result of T waits for the termination of the according thread. Unfortunately, this means that sometimes threads are bored:
foo a b = do
c <- fork $ f a
d <- fork $ g c
e <- fork $ h b
Here the execution of g c reserves a thread but starts with waiting for the evaluation of c. It would be certainly better to execute h b first. You may relax this problem by moving dependent actions away from another as much as possible. It would be optimal to have an OutOfOrder monad, but this is more difficult to implement. Although we fork all actions in order, the fork itself might re-order the actions. Thus the actions must not rely on a particular order other than the order imposed by data dependencies. We enforce with the NFData constraint that the computation is actually completed when the thread terminates. Currently the monad does not handle exceptions. It's certainly best to use a package with explicit exception handling like explicit-exception in order to tunnel exception information from the forked action to the main thread. Although fork has almost the same type signature as liftIO we do not define instance MonadIO InOrder.T since this definition would not satisfy the laws required by the MonadIO class.
Mirrors forkIO, but re-throws errors to the parent thread
  • Ignores manual thread kills, since those are on purpose.
  • Re-throws async exceptions (SomeAsyncException) as is.
  • Re-throws ExitCode as is in an attempt to exit with the requested code.
  • Wraps synchronous PseudoException in async ChildThreadError.
Fork a slave thread to run a computation on.
fork an independent process. It is equivalent to forkIO. The thread created is managed with the thread control primitives of transient
Start a new thread.
Cached measure of the whole node
Fork a thread and call the supplied function when the thread is about to terminate, with an exception or a returned value. The function is called with asynchronous exceptions masked.
forkFinally action and_then =
mask $ \restore ->
forkIO $ try (restore action) >>= and_then
This function is useful for informing the parent when a child terminates, for example.
Creates a new thread to run the IO computation passed as the first argument, and returns the ThreadId of the newly created thread. The new thread will be a lightweight, unbound thread. Foreign calls made by this thread are not guaranteed to be made by any particular OS thread; if you need foreign calls to be made by a particular OS thread, then use forkOS instead. The new thread inherits the masked state of the parent (see mask). The newly created thread has an exception handler that discards the exceptions BlockedIndefinitelyOnMVar, BlockedIndefinitelyOnSTM, and ThreadKilled, and passes all other exceptions to the uncaught exception handler. WARNING: Exceptions in the new thread will not be rethrown in the thread that created it. This means that you might be completely unaware of the problem if/when this happens. You may want to use the async library instead.