Safe Haskell | Safe-Inferred |
---|
Extra functions for Control.Concurrent. These functions manipulate the number of capabilities and new types of lock.
- module Control.Concurrent
- withNumCapabilities :: Int -> IO a -> IO a
- setNumCapabilities :: Int -> IO ()
- forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
- data Lock
- newLock :: IO Lock
- withLock :: Lock -> IO a -> IO a
- withLockTry :: Lock -> IO a -> IO (Maybe a)
- data Var a
- newVar :: a -> IO (Var a)
- readVar :: Var a -> IO a
- modifyVar :: Var a -> (a -> IO (a, b)) -> IO b
- modifyVar_ :: Var a -> (a -> IO a) -> IO ()
- withVar :: Var a -> (a -> IO b) -> IO b
- data Barrier a
- newBarrier :: IO (Barrier a)
- signalBarrier :: Barrier a -> a -> IO ()
- waitBarrier :: Barrier a -> IO a
- waitBarrierMaybe :: Barrier a -> IO (Maybe a)
Documentation
module Control.Concurrent
withNumCapabilities :: Int -> IO a -> IO aSource
On GHC 7.6 and above with the -threaded
flag, brackets a call to setNumCapabilities
.
On lower versions (which lack setNumCapabilities
) this function just runs the argument action.
setNumCapabilities :: Int -> IO ()
Set the number of Haskell threads that can run truly simultaneously
(on separate physical processors) at any given time. The number
passed to forkOn
is interpreted modulo this value. The initial
value is given by the +RTS -N
runtime flag.
This is also the number of threads that will participate in parallel garbage collection. It is strongly recommended that the number of capabilities is not set larger than the number of physical processor cores, and it may often be beneficial to leave one or more cores free to avoid contention with other processes in the machine.
forkFinally :: IO a -> (Either SomeException a -> IO ()) -> IO ThreadId
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.
modifyVar_ :: Var a -> (a -> IO a) -> IO ()Source
newBarrier :: IO (Barrier a)Source
signalBarrier :: Barrier a -> a -> IO ()Source
waitBarrier :: Barrier a -> IO aSource
waitBarrierMaybe :: Barrier a -> IO (Maybe a)Source