Guarantees regarding finalizers

Simon Marlow marlowsd at gmail.com
Mon Nov 30 09:45:48 EST 2009


On 26/11/2009 12:41, Mietek Bąk wrote:

> I'm writing a binding to a C library, which requires an explicit
> cleanup call before program termination.  While looking for a way to
> automatize this, I noticed a discrepancy in the standard library
> documentation.
>
> The Foreign.Concurrent documentation states:
> "The only guarantee is that the finalizer runs before the program terminates."
> (http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Concurrent.html)
>
> On the other hand, the Foreign.ForeignPtr documentation states:
> "Indeed, there is no guarantee that the finalizer is executed at all;
> a program may exit with finalizers outstanding."
> (http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-ForeignPtr.html)
>
> Note that Foreign.Concurrent.newForeignPtr is implemented in GHC as
> GHC.ForeignPtr.newConcForeignPtr.  The newConcForeignPtr comments also
> state:
> "There is no guarantee of promptness, and in fact there is no
> guarantee that the finalizer will eventually run at all."
> (http://www.haskell.org/ghc/docs/latest/html/libraries/base/src/GHC-ForeignPtr.html)
>
> As much as I would like the Foreign.Concurrent guarantee to be true,
> this seems to me like a documentation bug.

The docs are rather backward.  Foreign.ForeignPtr finalizers are 
guaranteed to run, Foreign.Concurrent finalizers are not.  I'll fix the 
docs, thanks for the report.

Cheers,
	Simon


More information about the Libraries mailing list