Guarantees regarding finalizers

Mietek Bąk mietek at
Thu Nov 26 07:41:26 EST 2009


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

The Foreign.Concurrent documentation states:
"The only guarantee is that the finalizer runs before the program terminates."

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."

Note that Foreign.Concurrent.newForeignPtr is implemented in GHC as
GHC.ForeignPtr.newConcForeignPtr.  The newConcForeignPtr comments also
"There is no guarantee of promptness, and in fact there is no
guarantee that the finalizer will eventually run at all."

As much as I would like the Foreign.Concurrent guarantee to be true,
this seems to me like a documentation bug.

Best regards,

Mietek Bąk

More information about the Libraries mailing list