[Haskell-cafe] getChar + System.Cmd.system + threads causes hangups
Einar Karttunen
ekarttun at cs.helsinki.fi
Mon Feb 20 11:17:49 EST 2006
Hello
Using system or any variant of it from System.Process
seems broken in multithreaded environments. This
example will fail with and without -threaded.
When run the program will print "hello: start" and
then freeze. After pressing enter (the first getChar)
System.Cmd.system will complete, but without that
it will freeze for all eternity.
What is the best way to fix this? I could use System.Posix,
but that would lose windows portablity which is needed.
import Control.Concurrent
import System.Cmd
main = do forkIO (threadDelay 100000 >> hello)
getChar
getChar
hello = do putStrLn "hello: start"
system "echo hello world!"
putStrLn "hello: done"
- Einar Karttunen
More information about the Haskell-Cafe
mailing list