Proposed change to ForeignPtr

George Russell ger at tzi.de
Tue Sep 10 13:17:42 EDT 2002


Malcolm Wallace wrote
[snip]
> 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.
[snip]
Unfortunately some sort of cascade is exactly what we want and need when
the Haskell finaliser indicates that Haskell is no longer interested in some
Foogle object, which means Foogle can run a GC which indicates Foogle is no
longer interested in some Haskell object and so on . . .

> 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.
[snip]
But surely Foogle has no way of knowing when the Haskell GC is over?
Suppose Haskell does

[enter GC]
...
[run finaliser 1]
...
[run finaliser 2]
...
[leave GC]

Then you want Foogle to delay any Haskell calls consequent on finaliser 1 until [leave GC],
don't you?  How can it?

Is it really so difficult to create some queue of delayed functions which can be appended
to from C and which nhc checks every time it does "leave GHC"?



More information about the FFI mailing list