Problem with hugs, concurrency and unsafeInterleaveIO (maybe a bug?)

Alastair Reid
Sun, 16 Mar 2003 21:04:43 +0000

> I am trying to lazily wait an MVar in hugs, in conjunction with
> concurrent haskell:
> [code snipped]
> I think that main2 should work, because in evaluating the result of
> f2, the main thread should suspend and yield.

Hugs creates a fresh scheduler instance for each invocation of
unsafePerformIO and unsafeInterleaveIO.  I think your code requires
threads to be able to 'migrate' from one scheduler instance to

Hugs can, perhaps, be made a little more flexible by maintaining a
single pool of runnable threads.  There are limits to how far we can
go though because (very roughly speaking) we have to be able to 'find'
the right instance of unsafePerformIO to 'awaken' when the relevant
thread completes.  The difficulty is that those instances are stored
on the C stack and must be awakened in the right order.

Alastair Reid         
Reid Consulting (UK) Limited