lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, 2005-01-05 at 08:36, Spencer Schumann wrote:

> It seems like the easiest fix would be to traverse the GC list twice
> when performing a sweep; on the first traversal, dead threads could be
> freed, and on the second traversal, everything else would be freed. 

The way to do this is much simpler. During the sweep
you collect objects for finalisation. You do not actually
finalise them and you definitely do not free them.

After the sweep is complete you finalise all the objects.

When that is done, then, and only then, you free up
all the objects.

Provided the finaliser doesn't cause unreachable object
to become reachable, this is entirely general.
[Add mods for managing weak arrays etc]

It is possible to avoid the multiple passes in several 
ways, using a flag or whatever.

It is also possible to handle finalisers that can
make unreachble objects reachble, however this
seems much easier with a collector that has
a write barrier. The Ocaml collector allows this.
I can't see how a naive mark/sweep can do this
without a phase delay flag.

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language