[Haskell-cafe] concurrency vs. I/O in GHC
donn at avvanta.com
Mon Oct 18 00:21:13 EDT 2010
[I wrote initially, ...]
> As I have migrated more of my application into Haskell, I find that
> I/O in one thread effectively blocks other threads.
Resolved - the SSL_read external I/O function needs to be "safe".
My apologies for botching the mailing list threading, but I deleted
the mail wherein someone helpfully asked whether I'd made my foreign
calls "safe" or "unsafe", and I can't see that message on the archives.
My initial take was, yes, of course I make external calls "safe",
because they sure are going to trigger callbacks into the Haskell
runtime and the documentation is quite clear about that.
However, I'd made SSL_read "unsafe", since no callbacks there.
Reversed that, and now my threads execute concurrently - SSL_read
doesn't block Haskell execution in all the other threads.
Either way, I can also report that it doesn't seem to matter whether
SSL_read was called from a callback, or not. If unsafe, it blocks
all the other threads either way, and if safe, it doesn't block them
So, thanks a lot, whoever you were! Henceforth I will play it safe
and eschew unsafeness. I vaguely recall a discussion here a ways back,
wherein the terms "safe" and "unsafe" were lamented and various confusing
propositions were bandied about. I should dig that up if I can, and
see if this practical example sheds some light on any of it.
Donn Cave, donn at avvanta.com
More information about the Haskell-Cafe