unsafePerformIO and cooperative concurrency

Simon Marlow simonmar at microsoft.com
Wed Apr 26 05:35:51 EDT 2006

On 26 April 2006 01:42, John Meacham wrote:

> It was pointed out that you can't necessarily know what routines to
> avoid in unsafePerformIO without mandating certain things _don't_ use
> concurrency, rather than that, how about the following:
> "Whether an implementation can yield to another thread inside an
> unsafePerformIO action is implementation dependent, however an
> implementation should not 'go wrong'"

Better, certainly.  I agree that rather than taling about "going wrong"
we should say "may not yield".  And concurrent foreign calls may not
behave concurrently, reentrant foreign calls may fail if they call back
to Haskell.

One common case (perhaps the only common case) where this happens is
hGetContents.  The lazy stream returned by hGetContents will not behave
in a non-blocking way in a cooperative implementation.  I can't decide
which demon to blame here: lazy I/O or cooperative concurrency :-)


More information about the Haskell-prime mailing list