
Hello. 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. Max.
participants (1)
-
Max A . K .