[Haskell-cafe] Re: A GHC error message puzzle

Tillmann Rendel rendel at Mathematik.Uni-Marburg.de
Fri Aug 13 12:00:55 EDT 2010

Simon Marlow wrote:
> So what happens is this:
>  - the recursive definition causes the main thread to block on itself
>    (known as a "black hole")
>  - the program is deadlocked (no threads to run), so the runtime
>    invokes the GC to see if any threads are unreachable
>  - the GC finds that
>    (a) the main thread is unreachable and blocked on a blackhole, so it
>        gets a NonTermination exception
>    (b) the Handle is unreachable, so its finalizer is started
>  - the finalizer runs first, and closes the Handle
>  - the main thread runs next, and the exception handler for writeFile
>    tries to close the Handle, which has already been finalized

Why is the Handle found unreachable? There seems to be a pointer to the 
Handle somewhere, which is later passed to the exception handler and 
used there. Why is that pointer not regarded by GC?

Is that situation Handle-specific, or could step (b) above free memory 
the exception handler is going to acess?

> Really hClose shouldn't complain about a finalized handle, I'll see if I can fix that. 

That sounds like a work-around to me, not a fix, because it would not 
fix more complicated exception handlers.


More information about the Haskell-Cafe mailing list