GC thread safe?

Martin v. Loewis martin at v.loewis.de
Thu Mar 14 16:53:10 EST 2002


Dieter Maurer <dieter at handshake.de> writes:

> Several Zope users face crashing Python 2.1.2 (SIGSEGV inside
> the garbage collector). The problem only occurs when
> the following conditions are true:
> 
>   *  Zope runs in multi-threaded mode
> 
>   *  the cyclic garbage collector is not deactivated
> 
> Is the cyclic garbage collector known to be thread safe?

The garbage collector runs while having the GIL, so it does not need
to be thread-safe. The only exception is when the garbage is cleared;
at this time, the collector holds an exclusive list of the garbage,
clearing one object after another. In principle, this may invoke the
garbage collector again (even from another thread). At that point,
the collector manipulates a list it has exclusive access to.

So yes, the cyclic garbage collector is thread-safe.

Regards,
Martin



More information about the Python-list mailing list