> "Simon Marlow" <[EMAIL PROTECTED]> writes:
> 
> > I think what's going on here is that the finalizer for 
> stdout is running
> > before your finalizer, and since stdout has already been 
> closed it can't
> > print out the message :-)
> 
> How is is possible for stdout to be finalised before putStrLn has run?
> Surely the closure for the putStrLn action holds a reference 
> to stdout,
> so stdout should remain live and not-GCed until after the putStrLn
> has completed?

You're right, this is a little strange.  There are actually two reasons
for this behaviour:

  - in GHC, references from a finalizer are treated as weak
    references, that is, they don't keep anything alive.  In our
    paper on weak pointers I seem to recall there was a good reason
    for this, but I'll need to go back and look it up again.  I'm
    beginning to think the decision seems a bit odd (after all, in
    the next GC, the references become non-weak again, because the
    finalizer is up and running).

  - at the end of execution, GHC just runs all the outstanding
    finalizers in any order.  So stdout might get finalized before
    another finalizer that refers to it.  I suppose we might do
    something better here: repeatedly GC and run finalizers until
    there are none left, perhaps.

Cheers,
        Simon

_______________________________________________
Cvs-ghc mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to