[MLton] adding synchronous finalizers

Henry Cejtin henry@sourcelight.com
Fri, 1 Oct 2004 15:43:34 -0500

Probably  just  being  silly, but your code creates new thunks and list pairs
every time the list of finalizers is run.  I  agree  that  from  a  semantics
point of view, it makes sense to check the value stored in synchronously ever
time an  individual  finalizer  is  called,  but  I  would  probably  add  an
optimization to check it in runFinalizers as well.  I.e., if synchronously is
true, then runFinalizers can  just  return  the  empty  list,  right?   (This
DEPENDS  on the fact that once runFinalizers is called in this state, nothing
else is going to be done that could set synchronusly to false until we return
to `user' code.)

I    would   argue   strongly   that   running   finalizers   when   I   call
setRunSynchronously with a true arg is bad.   It  isn't  semantically  wrong;
they  could  have  run  just before (assuming that it was false), but it is a
possibly expensive waste.  Again, I think of setting synchronously to true to
be like doing something atomically (although other things will happen).  If I
have  some  finalizers  waiting  to  fire,  and  then  I  set  things  to  be
synchronous,  they won't happen until either I manually call runFinalizers or
I stop being synchronous and a GC happens in that mode.