Proposed change to ForeignPtr

Malcolm Wallace Malcolm.Wallace at
Tue Sep 10 13:03:39 EDT 2002

George Russell <ger at> writes:

> Well, if the nhc98 RTS can't work out a time when it will be possible to
> run the delayed finalizer, how in creation do you expect the Foogle
> finalizer or whatever Foogle GC process it invokes to do so?

Quite simply, no finaliser (whether in Foogle or Haskell) should
be capable of triggering a garbage collection within its call.
This condition is absolutely necessary to prevent a cascade effect
of cross-language garbage collections, where a finaliser in Haskell
could trigger a GC in Foogle which triggers another (nested) GC in
Haskell etc.

Thus, if Haskell.freeSomething calls Foogle.freeSomething, and
Foogle.freeSomething cannot cause a Foogle GC, then no Foogle
finalisers are run yet, and so Foogle *cannot* call the Haskell world
until the Haskell GC is complete.  After that, it doesn't matter
when the Foogle finaliser decides to run.

Note that all of this assumes a sequential processing model, where
control is always with one of Foogle or Haskell, never both.  The FFI
spec explicitly avoids introducing any requirement for concurrency,
since it aims to be a minimal extension to H'98.


More information about the FFI mailing list