Concurrency problems with Handle

Simon Marlow simonmar at
Mon Dec 22 13:05:45 EST 2003

> Now, if I let one side of the connection send some characters:
>    sequence_ $ take 10 $ repeat $ (writeChan outputChan 's')
> and I let the other side consume them:
>    sequence_ $ take 10 $ repeat $ (putChar =<< readChan inputChan)
> then the characters are sent and received correctly, but the 
> receiving side 
> shows the characters only after the connection is closed.

This looks correct: stdout is probably buffered.  To see the characters
as they are written, hSetBuffering stdout NoBuffering.  If this doesn't
work, then there is probably some other buffereing going on somewhere
(don't run it in emacs, for example).

> If I let both sides send and consume characters in turn, like this:
>    sequence_ $ take 10 $ repeat $ threadDelay 250 >> 
> (writeChan outputChan 
> 's') >> (putChar =<< readChan inputChan)
> and
>    sequence_ $ take 10 $ repeat $ (putChar =<< readChan inputChan) >> 
> threadDelay 250 >> (writeChan outputChan 'c')
> , one character is sent, and the other end waits indefinitely before 
> sending his character.

Could be a bug.  Can you construct a complete program which illustrates
the problem, and send it to us?

> Could it have anything to with this?
> "One final note: the aaaa bbbb example may not work too well 
> on GHC....

I suspect that this is not the problem, since the case being referred to
in the docs here is where two running threads are competing for the same
resource, which doesn't seem to be the case in your code.


More information about the Glasgow-haskell-users mailing list