

Safe HaskellNone



This module exports:

  1. The MonadFork type class and its operations fork and forkOn.
  2. An instance of MonadFork for the IO monad.
  3. A universal pass-through instance of MonadFork for any existing MonadFork wrapped by a MonadLayerControl.
  4. The utility operations forkWithUnmask and forkOnWithUnmask.



class MonadMask m => MonadFork m whereSource

The MonadFork type class, for monads which support a fork operation.

An example of a monad which has a MonadFork instance that is not simply a lifted form of forkIO is the ResourceT monad from the resourcet package, which defines an operation resourceForkIO.


fork :: m () -> m ThreadIdSource

Sparks off a new thread to run the computation passed as the first argument, and returns the ThreadId of the newly created thread.

The new thread will be a lightweight thread; if you want to use a foreign library that uses thread-local storage, use forkOS instead. (Note that forkOS is not included in the MonadFork interface, so your monad m must be an instance of LiftControl 'IO m to be able to use forkOS.



forkOn :: Int -> m () -> m ThreadIdSource

Like fork, but lets you specify on which processor the thread should run. Unlike a fork thread, a thread created by forkOn will stay on the same processor for its entire lifetime (fork threads can migrate between processors according to the scheduling policy). forkOn is useful for overriding the scheduling policy when you know in advance how best to distribute the threads.



forkWithUnmask :: MonadFork m => ((forall a n. MonadMask n => n a -> n a) -> m ()) -> m ThreadIdSource


  ... mask_ $ forkIOWithUnmask $ \unmask ->
                 catch (unmask ...) handler



forkOnWithUnmask :: MonadFork m => Int -> ((forall a n. MonadMask n => n a -> n a) -> m ()) -> m ThreadIdSource

Like forkWithUnmask, but the child thread is pinned to the given CPU, as with forkOn.