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

Wei Hu wei.hoo at gmail.com
Fri Aug 13 14:02:02 EDT 2010


On Fri, Aug 13, 2010 at 4:53 AM, Simon Marlow <marlowsd at gmail.com> wrote:
> Ah yes, that works too.  But other similar versions don't, like this one:
>
> process :: String ->  String
> process _ = let x = x in x
>
> Hence why I added the "tail" in my version.

Without "-O", this version doesn't work, but with "-O" it does. Why?

>
> 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
>
> Really hClose shouldn't complain about a finalized handle, I'll see if I can
> fix that.
>
> Cheers,
>        Simon
>


More information about the Haskell-Cafe mailing list