
Hello, I am playing around with concurrency using ghc 5.02.2. What I'd like to do is have a bunch of threads do something indefinitely, while one thread monitors stdin for user input (the user input affects the behavior of the other threads in some way). From the documentation I had assumed that standard Haskell I/O functions (like getline) would not block other running threads, but this doesn't seem to be the case as illustrated here: conTry3 = forkIO (loop 'a') >> quitYet where loop ch = hPutChar stdout ch >> loop ch quitYet = do x <- getLine if x == "quit" then return () else quitYet Output: (stuff in between {} is a comment, and not part of the output) rere ttt fff dfsd fgfg fgfg aaaaaaaaaaaaaaaaaa { and on and on } dfdf dfd fdfd fgfg fgf aaaaaaaaaaaaaaaa { and on and on } quit aaaaaaa { and on and on } {program ends} The behavior I wanted was for 'a' to be printed (almost) continuously, echo the relatively infrequent input, and quit upon receiving "quit". I am aware (through a web search) that there was a mail thread addressing a similar issue a while back (1999) entitled: I thought concurrent haskell was _preemptive_! That thread made it seem like the issue would be cleared up soon. In any case, I would still like to be able to have an interactive input thread that doesn't block everything in my program. Is there any way to do this? Thanks in advance, Walker

Hi, I suspect you're using ghc on a win32 platform. ghc-win32 doesn't presently support non-blocking I/O, hence the behaviour you're seeing. --sigbjorn ----- Original Message ----- From: Walker Duhon To: glasgow-haskell-users@haskell.org Sent: Wednesday, October 30, 2002 18:02 Subject: Concurrency and interactive input Hello, I am playing around with concurrency using ghc 5.02.2. What I'd like to do is have a bunch of threads do something indefinitely, while one thread monitors stdin for user input (the user input affects the behavior of the other threads in some way). From the documentation I had assumed that standard Haskell I/O functions (like getline) would not block other running threads, but this doesn't seem to be the case as illustrated here: conTry3 = forkIO (loop 'a') >> quitYet where loop ch = hPutChar stdout ch >> loop ch quitYet = do x <- getLine if x == "quit" then return () else quitYet Output: (stuff in between {} is a comment, and not part of the output) rere ttt fff dfsd fgfg fgfg aaaaaaaaaaaaaaaaaa { and on and on } dfdf dfd fdfd fgfg fgf aaaaaaaaaaaaaaaa { and on and on } quit aaaaaaa { and on and on } {program ends} The behavior I wanted was for 'a' to be printed (almost) continuously, echo the relatively infrequent input, and quit upon receiving "quit". I am aware (through a web search) that there was a mail thread addressing a similar issue a while back (1999) entitled: I thought concurrent haskell was _preemptive_! That thread made it seem like the issue would be cleared up soon. In any case, I would still like to be able to have an interactive input thread that doesn't block everything in my program. Is there any way to do this? Thanks in advance, Walker
participants (2)
-
Sigbjorn Finne
-
Walker Duhon