
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

On Mon, Oct 15, 2001 at 04:47:25PM +0100, Simon Marlow wrote:
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?
I test your example. It doesn't work for me. Both for 5.00.1 and 5.00.2. That's glibc-2.0.7/linux-2.2.19/x86 (does it matter?). Tried both with '-O -fglasgow-exts' and no options. I't quite stable behavior. that's what strace told me: succeeded case: ------------ cut begin
gettimeofday({1002682961, 979251}, NULL) = 0 select(1, [0], [], NULL, {0, 0}) = 0 (Timeout) gettimeofday({1002682961, 980192}, NULL) = 0 write(1, "tick\n", 5) = 5 gettimeofday({1002682961, 981179}, NULL) = 0 gettimeofday({1002682961, 981525}, NULL) = 0 select(1, [0], [], NULL, {1, 0}) = 0 (Timeout) gettimeofday({1002682962, 980292}, NULL) = 0 [skipped] select(1, [0], [], NULL, {0, 0}) = 0 (Timeout) gettimeofday({1002682963, 162}, NULL) = 0 write(1, "tick\n", 5) = 5 gettimeofday({1002682963, 1134}, NULL) = 0 gettimeofday({1002682963, 1497}, NULL) = 0 select(1, [0], [], NULL, {1, 0}) = 0 (Timeout) gettimeofday({1002682964, 433}, NULL) = 0 [skipped..repeated several times] select(1, [0], [], NULL, {0, 0}) = 0 (Timeout) gettimeofday({1002682964, 20740}, NULL) = 0 write(1, "tick\n", 5) = 5 gettimeofday({1002682964, 21560}, NULL) = 0 gettimeofday({1002682964, 21876}, NULL) = 0 select(1, [0], [], NULL, {1, 0}) = 1 (in [0], left {0, 250000}) read(0, "qwertrt\n", 8192) = 8 write(1, "qwertrt\n", 8) = 8 read(0, 0x8079f80, 8192) = -1 EAGAIN (Resource temporarily unavailable) gettimeofday({1002682964, 772256}, NULL) = 0 select(1, [0], [], NULL, {0, 260000}) = 0 (Timeout) gettimeofday({1002682965, 30227}, NULL) = 0 select(1, [0], [], NULL, {0, 0}) = 0 (Timeout) ------------ cut end
failed case: ------------ cut begin
brk(0x8085000) = 0x8085000 write(1, "tick\n", 5) = 5 gettimeofday({1002682710, 783155}, NULL) = 0 gettimeofday({1002682710, 783502}, NULL) = 0 select(0, [], [], NULL, {0, 0}) = 0 (Timeout) read(4, "click\n", 8192) = 6 write(1, "click\n", 6) = 6 read(4, "click\n", 8192) = 6 write(1, "click\n", 6) = 6 ------------ cut end
I didn't try ghc-5.02 since I haven't installed it yet. Max.
participants (2)
-
Max Kirillov
-
Simon Marlow