#3542: ghc-cabal deadlocks
---------------------------------+------------------------------------------
    Reporter:  igloo             |        Owner:                  
        Type:  bug               |       Status:  new             
    Priority:  high              |    Milestone:  6.12.1          
   Component:  Build System      |      Version:  6.10.4          
    Severity:  normal            |   Resolution:                  
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:                    |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Comment (by simonmar):

 I mentioned this to Ian this morning on the phone, but just to record it
 here: it is indeed possible to write this code correctly using the single-
 threaded RTS, an example of how to do so is the implementation of
 `readProcess` and `readProcessWithExitCode` in recent versions of
 `System.Process`.  Here's a snippet:

 {{{
 readProcess cmd args input = do
     (Just inh, Just outh, _, pid) <-
         createProcess (proc cmd args){ std_in  = CreatePipe,
                                        std_out = CreatePipe,
                                        std_err = Inherit }

     -- fork off a thread to start consuming the output
     output  <- hGetContents outh
     outMVar <- newEmptyMVar
     _ <- forkIO $ C.evaluate (length output) >> putMVar outMVar ()

     -- now write and flush any input
     when (not (null input)) $ do hPutStr inh input; hFlush inh
     hClose inh -- done with stdin

     -- wait on the output
     takeMVar outMVar
     hClose outh

     -- wait on the process
     ex <- waitForProcess pid

     ...
 }}}

 the idea is that you block on an `MVar` instead of in `waitForProcess`.
 This assumes that if the process goes away then the pipe will also go away
 and the threads will stop.  Actually I think the code should be using
 `finally` to make sure the `MVar` gets written even if an exception is
 raised.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3542#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to