[Haskell-cafe] strange hangs with -threaded runtime (now with test case)

Joey Hess joey at kitenet.net
Sat Jul 14 20:24:47 CEST 2012

I've found a minimal test case that seems to demonstrate a bug in either
MissingH or ghc's threaded runtime. Or I'm doing something stupid in
fewer lines of code than usual. ;)

When built with the threaded runtime, after a short while it hangs in

import System.Cmd
import System.IO
import System.Cmd.Utils
import System.Posix.Process
import Control.Monad

main :: IO ()
main = forever $ pipeRead ["hello", "world"]

pipeRead :: [String] -> IO ()
pipeRead params = do
	-- removing this next line avoids the hang somehow
        print $ "pipeRead in " ++ show params
        (p, h) <- hPipeFrom "echo" params
        print "pipeRead getcontents"
        c <- hGetContents h
        print $ "got: " ++ c
        _ <- getProcessStatus True False $ processID p
	-- removing this last line avoids the hang somehow
        print "pipeRead out"

joey at wren:~>ghc --make -threaded test
[1 of 1] Compiling Main             ( test.hs, test.o )
Linking test ...
joey at wren:~>./test
"pipeRead in [\"hello\",\"world\"]"
"pipeRead getcontents"
"got: hello world\n"
"pipeRead out"
"pipeRead in [\"hello\",\"world\"]"
"pipeRead getcontents"
"got: hello world\n"
"pipeRead out"
<snip 20 repeats>
"pipeRead in [\"hello\",\"world\"]"
"pipeRead getcontents"

Ghc 7.4.2, Debian Linux

see shy jo

More information about the Haskell-Cafe mailing list