[ANNOUNCE] Garbage collection for Python

Helge Hess helge.hess at mdlink.de
Tue Apr 11 13:14:25 EDT 2000


Bjorn Pettersen wrote:
> Helge Hess wrote:
> > I think what he wants to do (me too ;-) is to run several copies of the
> > interpreter in *one* process, possibly in multiple threads.
> > But I'm not sure whether this is a GC issue though (RC isn't thread-safe
> > anyway, right ?).
> 
> Well, it actually can be -- at least on Windows :-)

The question is, what overhead is involved here. If these Windows
functions wrap the RC ops in locks you have gained nothing (wrapping RCs
in locks breaks performance in a big way). Note that std-RC is often
only one CPU op (incr,decr).

Also note that not only the ++ or -- needs to be protected, but the
'==0' check as well. Eg:

   [task1]            [task2]
   dec(obj);          inc(obj);
could be
   [task1]	      [task2]
   obj->rc--;	      
   if (obj->rc==0)
     <task-switch>    obj->rc++;
     free(obj);       <task-switch>
   object-freed	      assumes to have a valid obj

[note that checking for 0 in task2 doesn't solve the problem, since the
check wouldn't be atomic again, but maybe I'm missing something].

A (m&s) GC is somewhat in advantage here, since it is run only at
specified (safe) points, so there is no locking required at such high
frequency.

Helge




More information about the Python-list mailing list