Guarantees regarding finalizers
mietek at gmail.com
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.
More information about the Libraries