[Haskell-cafe] BlockedIndefinitelyOnMVar exception

Neil Brown nccb2 at kent.ac.uk
Thu Mar 31 12:15:32 CEST 2011


On 31/03/11 11:03, Gregory Collins wrote:
> I'm guessing the trigger condition for
> "BlockedIndefinitelyOnMVar" is "blocked and mvar refcount == 1"
It's not simply a reference count (the thread that's blocked forever can 
hold multiple references to the MVar and it's still blocked 
indefinitely).  Here's how I understand it.

Blocked threads are not counted as roots during the GC.  Therefore for a 
blocked thread to survive a round of GC without being collected, 
something reachable from a root has to point to the thread.  The only 
thing that points to a thread blocked on an MVar (same idea for TVars, 
too) is the MVar itself.  Therefore, something that's reachable from a 
GC root (a running thread is a root, I think) must point to the MVar to 
allow the thread to survive the GC.  If a thread would be garbage 
collected, it is instead woken up with a BlockedIndefinitelyOnMVar 
exception.

I think if you put an MVar into a StablePtr, that may prevent threads 
waiting on it from being woken up with that exception.

Thanks,

Neil.



More information about the Haskell-Cafe mailing list