> I have the following relatively simple concurrent haskell program:
>
> import IO
> import Concurrent
>
> main =
> let
> loop ch = hPutChar stdout ch >> loop ch
> in
> forkIO (loop 'a') >> (let booga = (do
> out <- hGetLine stdin
> hPutStrLn stdout out
> booga)
> in
> booga)
>
> Now, the expected results of this would be that it would
> print out a lot
> of 'a' characters and if you happened to type something else
> in, it would
> echo that as well somewhere in the midst. HOWEVER, it seems
> with ghc 4.02
> either this is not the case (and concurrent haskell is
> basically useless)
> or I'm doing something horribly wrong. Here's what happens
> when I run the
> above code:
>
> $ ./loopa
> aeunt
> aeunt
> hello
> hello
> ?
> ?
> it
> it
>
> is anyone home?
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaais anyone home?
> grrrr
> grrrr
> ^C
> $
>
> As you can see, the input/echo process seems to be the only
> one running
> initially, then the 'a' printing loop wakes up just long
> enough to spit
> out a chunk of characters before going back to sleep. So, as
> far as I can
> tell, there is no way to have a blocked listening process
> lurking in the
> background on a stream, because that blocking will halt all other
> processing in the haskell program! What's wrong here?
The problem here is that the Concurrent Haskell implementation in ghc-4.02
can't preempt a thread that's blocked on I/O. We're working on a temporary
fix using the threadWait{Read,Write} primitives from pre-4.00 versions of
GHC (right, Sigbjorn? :-). The real fix will probably involve using OS
threads on systems that support them, and this is something we definitely
want to support.
Cheers,
Simon