
Playing with GHC, I met some oddity. Consider the example:
import IO import Concurrent import Posix import PosixIO
main = do (fdIn, fdIn_send) <- createPipe hIn_send <- fdToHandle fdIn_send hIn <- fdToHandle fdIn -- The "waiter" is a simple tk/tcl script which -- prints "click" anytime I click a button. runProcess "./waiter" [] Nothing Nothing Nothing (Just hIn_send) Nothing -- hSetBuffering hIn LineBuffering {-2-} -- hSetBuffering stdin LineBuffering forkIO(interact stdin) -- forkIO(interact hIn) {-1-} main_cycle where interact hIn = do line <- hGetLine hIn numIn <- handleToInt {-made from handleToFd & fdToInt-} -- threadWaitRead numIn {-3-} putStrLn line interact hIn main_cycle = do putStrLn "tick" threadDelay 1000000 main_cycle
The example works OK. It prints "tick" once a second and dups my input as I type it. But, when I uncomment the line {-1-} to handle input from child as well, everything is hanged on this read operation. Uncommenting the {-3-} line helps, but, first, I'm not sure it is a right way and, second, the matter is still unclear - what is the reason of such difference?
Uncommenting the {-2-} lines doesn't help. I thing the reason is in some inner properties of the handlers, but have no idea in which one.
I tried this here on Linux/x86 with 5.02 and it seems to work fine. Instead of the tcl/tk script you mentioned I used a FIFO in /tmp/fifo and made the runProcess just call "cat /tmp/fifo". Which GHC version and platform is this on? Cheers, Simon