Guarantees regarding finalizers
Mietek Bąk
mietek at gmail.com
Thu Nov 26 07:41:26 EST 2009
Hello,
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.
Best regards,
--
Mietek Bąk
More information about the Libraries
mailing list