forkIO,
#ifdef __GLASGOW_HASKELL__
- forkIOUnmasked,
+ forkIOWithUnmask,
killThread,
throwTo,
#endif
forkOS,
isCurrentThreadBound,
runInBoundThread,
- runInUnboundThread
+ runInUnboundThread,
#endif
-- * GHC's implementation of concurrency
-- ** Pre-emption
-- $preemption
+
+ -- * Deprecated functions
+ forkIOUnmasked
+
) where
import Prelude
#ifdef __GLASGOW_HASKELL__
import GHC.Exception
-import GHC.Conc ( ThreadId(..), myThreadId, killThread, yield,
- threadDelay, forkIO, forkIOUnmasked, childHandler )
+import GHC.Conc hiding (threadWaitRead, threadWaitWrite)
import qualified GHC.Conc
import GHC.IO ( IO(..), unsafeInterleaveIO, unsafeUnmask )
import GHC.IORef ( newIORef, readIORef, writeIORef )
, UnliftedFFITypes
, ForeignFunctionInterface
, DeriveDataTypeable
+ , RankNTypes
#-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_HADDOCK not-home #-}
-- * Forking and suchlike
, forkIO -- :: IO a -> IO ThreadId
, forkIOUnmasked
+ , forkIOWithUnmask
, forkOnIO -- :: Int -> IO a -> IO ThreadId
, forkOnIOUnmasked
+ , forkOnIOWithUnmask
, numCapabilities -- :: Int
, getNumCapabilities -- :: IO Int
, numSparks -- :: IO Int
where
action_plus = catchException action childHandler
--- | Like 'forkIO', but the child thread is created with asynchronous exceptions
--- unmasked (see 'Control.Exception.mask').
+{-# DEPRECATED forkIOUnmasked "use forkIOWithUnmask instead" #-}
+-- | This function is deprecated; use 'forkIOWIthUnmask' instead
forkIOUnmasked :: IO () -> IO ThreadId
forkIOUnmasked io = forkIO (unsafeUnmask io)
+-- | Like 'forkIO', but the child thread is passed a function that can
+-- be used to unmask asynchronous exceptions. This function is
+-- typically used in the following way
+--
+-- > ... mask_ $ forkIOWithUnmask $ \unmask ->
+-- > catch (unmask ...) handler
+--
+-- so that the exception handler in the child thread is established
+-- with asynchronous exceptions masked, meanwhile the main body of
+-- the child thread is executed in the unmasked state.
+--
+-- Note that the unmask function passed to the child thread should
+-- only be used in that thread; the behaviour is undefined if it is
+-- invoked in a different thread.
+--
+forkIOWithUnmask :: ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId
+forkIOWithUnmask io = forkIO (io unsafeUnmask)
+
{- |
Like 'forkIO', but lets you specify on which CPU the thread is
created. Unlike a `forkIO` thread, a thread created by `forkOnIO`
where
action_plus = catchException action childHandler
--- | Like 'forkOnIO', but the child thread is created with
--- asynchronous exceptions unmasked (see 'Control.Exception.mask').
+{-# DEPRECATED forkOnIOUnmasked "use forkOnIOWithUnmask instead" #-}
+-- | This function is deprecated; use 'forkOnIOWIthUnmask' instead
forkOnIOUnmasked :: Int -> IO () -> IO ThreadId
forkOnIOUnmasked cpu io = forkOnIO cpu (unsafeUnmask io)
+-- | Like 'forkIOWithUnmask', but the child thread is pinned to the
+-- given CPU, as with 'forkOnIO'.
+forkOnIOWithUnmask :: Int -> ((forall a . IO a -> IO a) -> IO ()) -> IO ThreadId
+forkOnIOWithUnmask cpu io = forkOnIO cpu (io unsafeUnmask)
+
-- | the value passed to the @+RTS -N@ flag. This is the number of
-- Haskell threads that can run truly simultaneously at any given
-- time, and is typically set to the number of physical CPU cores on