Finalizers: the Legend that Won't Die
ger at tzi.de
Thu Feb 27 12:24:01 EST 2003
Manuel wrote (snipped)
> I have just read Hans Boehm's POPL paper on finalizers. His
> suggestion for the use of finalizers in single-threaded
> systems is to provide a `runFinalizers' routine, instead of
> relying on the asynchronous execution that, as established,
> requires support for concurrency. I am not sure whether we
> have given this option really serious consideration.
I can only see one problem with this. Suppose you have the following
sequence of events:
x = seq (unsafePerformIO runFinalizers) y
finalizer = [... something involving x ...]
[... attach finalizer to something ..]
[... something becomes free, putting finalizer on the to-be-done list ...]
[.., computation requiring x ...]
Then during the computation of x the following things are liable to happen:
(1) Evaluation of x begins. x is blackholed.
(2) runFinalizers is invoked.
(3) "finalizer" is begun.
(4) finalizer needs value of x. Ooops, what do we do now?
Is it safe to run runFinalizers anywhere except in the main IO trunk? Otherwise you
always have the risk of coming a cropper on blackholed values, don't you?
More information about the FFI