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

I am trying to lazily wait an MVar in hugs, in conjunction with concurrent haskell: ----- import Concurrent import IOExts f = do v <- newEmptyMVar c <- getContents forkIO (putMVar v (head c)) r <- unsafeInterleaveIO (takeMVar v) return v f2 = f >>= unsafeInterleaveIO . takeMVar main1 = f >>= takeMVar >>= print main2 = f2 >>= print main3 = f2 >>= (\ x -> yield >> print x) ----- main1 and main3 work flawlessly, but main2 aborts with "no more threads to run". I think that main2 should work, because in evaluating the result of f2, the main thread should suspend and yield. Is there somebody who wants to enlighten me? Vincenzo

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 another. 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 alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/
participants (2)
-
Alastair Reid
-
Nick Name