module SlaveThread.Util.LowLevelForking where

import SlaveThread.Prelude

-- |
-- A more efficient version of 'forkIO',
-- which does not install a default exception handler on the forked thread.
{-# INLINE forkIOWithoutHandler #-}
forkIOWithoutHandler :: IO () -> IO ThreadId
forkIOWithoutHandler :: IO () -> IO ThreadId
forkIOWithoutHandler (IO State# RealWorld -> (# State# RealWorld, () #)
action) =
  forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> case (forall a.
a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
fork# State# RealWorld -> (# State# RealWorld, () #)
action State# RealWorld
s) of (# State# RealWorld
s', ThreadId#
tid #) -> (# State# RealWorld
s', ThreadId# -> ThreadId
ThreadId ThreadId#
tid #)