Why doesn't GHC force a GC before program quits?

Simon Marlow marlowsd at gmail.com
Tue Apr 10 14:54:17 CEST 2012


On 03/04/2012 21:40, Paul Liu wrote:
> It seems to violate the claim that "all finalizers are run exactly
> once" mentioned in the weak pointer paper. Is there any reason not to
> enforce this?

GHC does do a GC before the program quits, but it doesn't wait for all 
the finalizers to finish.  It turns out to be difficult to do that: the 
runtime doesn't know the difference between a finalizer thread and an 
ordinary thread, and we don't normally wait for ordinary threads to 
finish before terminating the program.  What about blocked finalizers? 
What if the finalizers create more finalizers?  It's all a bit of a 
swamp.  So now we just don't guarantee that (Haskell) finalizers run 
before program exit; if you want guaranteed execution then you can use C 
finalizers.

Some of the motivation for this change comes from Hans Boehm's seminal 
paper on finalizers:

http://www.hpl.hp.com/techreports/2002/HPL-2002-335.html

Cheers,
	Simon



More information about the Cvs-ghc mailing list