unsafeInterleaveIO

Ross Paterson ross@soi.city.ac.uk
Mon, 11 Aug 2003 12:04:40 +0100


On Mon, Aug 11, 2003 at 11:11:38AM +0100, Simon Marlow wrote:
> Can't you implement it like this:
> 
>   unsafeInterleaveIO io = return (unsafePerformIO io)

That's exactly what's there now, and it doesn't produce interleaving.
Hugs doesn't have a global thread pool -- each instance of unsafePerformIO
has its own.  Once the side computation starts, it runs to completion
before returning to the main thread.  Even if it yields, only threads
spawned inside the unsafePerformIO can take over.  A global thread pool
doesn't seem feasible with the current implementation of concurrency
in Hugs.  Concurrency is implemented in the libraries; a blocked thread
is a continuation, and it's not clear how to construct that continuation
in a pure context.