- Rename System.Posix.Process.forkProcess to forkProcessAll
- Move GHC.Conc.forkProcess to System.Posix with type 'Maybe ProcessID'
Prompted by: George Russel
, yield -- :: IO ()
, labelThread -- :: ThreadId -> String -> IO ()
, forkProcessPrim -- :: IO Int
, yield -- :: IO ()
, labelThread -- :: ThreadId -> String -> IO ()
, forkProcessPrim -- :: IO Int
- , forkProcess -- :: IO (Maybe Int)
-- Waiting
, threadDelay -- :: Int -> IO ()
-- Waiting
, threadDelay -- :: Int -> IO ()
import GHC.Base
import GHC.IOBase ( IO(..), MVar(..), ioException, IOException(..), IOErrorType(..) )
import GHC.Num ( fromInteger, negate )
import GHC.Base
import GHC.IOBase ( IO(..), MVar(..), ioException, IOException(..), IOErrorType(..) )
import GHC.Num ( fromInteger, negate )
+import GHC.Real ( fromIntegral )
import GHC.Base ( Int(..) )
import GHC.Exception ( Exception(..), AsyncException(..) )
import GHC.Pack ( packCString# )
import GHC.Base ( Int(..) )
import GHC.Exception ( Exception(..), AsyncException(..) )
import GHC.Pack ( packCString# )
adr = byteArrayContents# ps in
case (labelThread# t adr s) of s1 -> (# s1, () #)
adr = byteArrayContents# ps in
case (labelThread# t adr s) of s1 -> (# s1, () #)
-{- | This function is a replacement for "Posix.forkProcess": This implementation
-/will stop all other Concurrent Haskell threads/ in the (heavyweight) forked copy.
-'forkProcessPrim' returns the pid of the child process to the parent, 0 to the child,
-and a value less than 0 in case of errors. See also: 'forkProcess'.
+{- | This function is a replacement for "System.Posix.Process.forkProcessAll":
+This implementation /will stop all other Concurrent Haskell threads/ in the
+(heavyweight) forked copy.
+'forkProcessPrim' returns the pid of the child process to the parent, 0 to the
+child, and a value less than 0 in case of errors. See also:
+'System.Posix.Process.forkProcess' in package @unix@.
Without this function, you need excessive and often impractical
explicit synchronization using the regular Concurrent Haskell constructs to assure
Without this function, you need excessive and often impractical
explicit synchronization using the regular Concurrent Haskell constructs to assure
To work around this problem, call 'forkProcessPrim' from the main thread.
-}
To work around this problem, call 'forkProcessPrim' from the main thread.
-}
+-- XXX RTS should know about 'pid_t'.
+
forkProcessPrim :: IO Int
forkProcessPrim = IO $ \s -> case (forkProcess# s) of (# s1, id #) -> (# s1, (I# id) #)
forkProcessPrim :: IO Int
forkProcessPrim = IO $ \s -> case (forkProcess# s) of (# s1, id #) -> (# s1, (I# id) #)
-{- | 'forkProcess' is a wrapper around 'forkProcessPrim' similar to the one found in
-"Posix.forkProcess" which returns a Maybe-type. The child receives @Nothing@, the
-parent @Just (pid::Int)@. In case of an error, an exception is thrown.
-
-NOTE: currently, main threads are not stopped in the child process.
-To work around this problem, call 'forkProcess' from the main thread.
--}
-
-forkProcess :: IO (Maybe Int)
-forkProcess = do
- pid <- forkProcessPrim
- case pid of
- -1 -> ioException (IOError Nothing -- stolen from hslibs/posix/PosixUtil
- SystemError
- "forkProcess"
- ""
- Nothing)
- 0 -> return Nothing
- _ -> return (Just pid)
-
-- Nota Bene: 'pseq' used to be 'seq'
-- but 'seq' is now defined in PrelGHC
--
-- Nota Bene: 'pseq' used to be 'seq'
-- but 'seq' is now defined in PrelGHC
--