[Gd-hackers] Gwydion Dylan on MacOS X

Thomas Christian Chust chust at web.de
Tue Nov 13 14:35:15 CET 2007


Bruce Hoult wrote:

> [...] Because the design in Boehm is to by default run
> finalizers synchronously from inside the garbage collector, *any*
> memory allocation call can (and will, one day) run finalizers.  If
> you're not incredibly careful in maintaining your cleanup list then
> this will eventually cause  corruption when finalizers are run
> removing things from that list in the middle of other code adding
> things to the list. [...]

Hello,

as far as I can see, there are two solutions to this problem:

  1) Create a list yourself which you update from the registered
     finalization functions with some mechanism like conditional-update!
     (as you said, locking data structures is not an option) and drain
     this list from a separate thread or from some kind of program main
     event loop -- this is what OpenDylan does, because the interface
     for the runtime is then uniform no matter whether MPS or the
     Boehm-Demers-Weiser collector are used.

  2) Set GC_finalize_on_demand = 1 and let the Boehm-Demers-Weiser
     collector maintain the finalization list for you. Then call
     GC_run_finalizers from a separate thread or from some kind of
     program main event loop to drain the list -- this is what my
     little library does.

Of course the automatic finalization thread cannot be enabled in single
threaded Dylan, so you have to call drain-finalization-queue manually
somewhere in your program -- presumably from the main loop of a GUI
application or in the initialization method of certain objects.

But this approach should be quite transparent also when debugging your
program.


cu,
Thomas



More information about the hackers mailing list