Question about Python threads

brueckd at tbye.com brueckd at tbye.com
Mon Aug 26 17:30:14 CEST 2002


On 26 Aug 2002, Ville Vainio wrote:

> > In Python, everything is an object, including ints, ... so two threads
> > manipulating the refcount of an object at the same time will certainly
> > crash the interpreter sooner or later. AFAIK Java objects don't have
> > refcounts, right?
> 
> Yes, Java uses garbage collection. On a related note: could GIL be
> dumped if refcounts were no longer used (ie Python changed over to gc
> instead)?

Well, refcounts _are_ a method of gc, but either way the answer is still
'no'. ;-)

The two issues are pretty much unrelated: the GIL ensures that
Python's internal state doesn't get wacky in multithreaded programs, and
most of the benefit of the GIL comes while objects are still "alive" (in
use by someone). 

Refcounting/other GC methods apply to single- _and_ multi-threaded
programs, and their benefit comes when it's time for objects to "die" - 
knowing what is safe to destroy and when to do it.

-Dave





More information about the Python-list mailing list