[Haskell-cafe] Re: Are handles garbage-collected?

Simon Marlow simonmar at microsoft.com
Tue Oct 26 06:36:58 EDT 2004

On 26 October 2004 10:42, Malcolm Wallace wrote:

> "Simon Marlow" <simonmar at microsoft.com> writes:
>> I didn't mean fully synchronous, just "more synchronous".  For
>> example, the finalization routine could be run directly after
>> garbage collection. Hugs & nhc98 already do this, because they don't
>> support Haskell finalizers.
> Actually, nhc98 supports both C and Haskell finalisers, with the same
> signatures as in ghc:
>     newForeignPtr     :: FinalizerPtr a -> Ptr a -> IO (ForeignPtr a)
>     newConcForeignPtr :: IO ()          -> Ptr a -> IO (ForeignPtr a)
> C finalisers are run during garbage collection, Haskell finalisers
> are run immediately afterwards.  In fact, you cannot run a Haskell
> finaliser during GC, because you don't have a valid heap to run it in.

But don't you run into problems in the implementation of
newConcForeignPtr, when the Haskell finalizer needs the value of a thunk
that was already under evaluation when the GC happened?  ie. the need
for concurrency that stopped this from becoming part of the official


More information about the Haskell-Cafe mailing list