[commit: packages/process] master: Add comments (3f3566f)

git at git.haskell.org git at git.haskell.org
Wed Jul 19 21:19:15 UTC 2017


Repository : ssh://git@git.haskell.org/process

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/3f3566f23539863cf1d6e45261651fa4a46ff5b9/process

>---------------------------------------------------------------

commit 3f3566f23539863cf1d6e45261651fa4a46ff5b9
Author: Charles Cooper <cooper.charles.m at gmail.com>
Date:   Sat Feb 4 15:39:42 2017 -0500

    Add comments


>---------------------------------------------------------------

3f3566f23539863cf1d6e45261651fa4a46ff5b9
 System/Process.hs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/System/Process.hs b/System/Process.hs
index b78b831..50c787e 100644
--- a/System/Process.hs
+++ b/System/Process.hs
@@ -590,6 +590,7 @@ waitForProcess ph@(ProcessHandle _ delegating_ctlc _) = lockWaitpid $ do
     ClosedHandle e -> return e
     OpenHandle h  -> do
         e <- alloca $ \pret -> do
+          -- don't hold the MVar while we call c_waitForProcess...
           throwErrnoIfMinus1Retry_ "waitForProcess" (c_waitForProcess h pret)
           modifyProcessHandle ph $ \p_' ->
             case p_' of
@@ -613,7 +614,13 @@ waitForProcess ph@(ProcessHandle _ delegating_ctlc _) = lockWaitpid $ do
 #else
         return $ ExitFailure (-1)
 #endif
-  where lockWaitpid m = withMVar (waitpidLock ph) $ \() -> m
+  where
+    -- If more than one thread calls `waitpid` at a time, `waitpid` will
+    -- return the exit code to one of them and (-1) to the rest of them,
+    -- causing an exception to be thrown.
+    -- Cf. https://github.com/haskell/process/issues/46, and
+    -- https://github.com/haskell/process/pull/58 for further discussion
+    lockWaitpid m = withMVar (waitpidLock ph) $ \() -> m
 
 -- ----------------------------------------------------------------------------
 -- getProcessExitCode



More information about the ghc-commits mailing list