Question about Python threads

Ville Vainio vvainio at tp.spt.fi
Wed Aug 28 06:26:21 EDT 2002


brueckd at tbye.com wrote in message news:<mailman.1030372004.29144.python-list at python.org>...

> > 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'. ;-)

GC is often thought of as an alternative to refcounting - obviously
it's another method of automatic resource deallocation, but they are
often thought of as seperate things.

> The two issues are pretty much unrelated: the GIL ensures that

My point was that reference counting is something that obviously
requires locking, while other uses of GIL might be less compulsory.
This thought was further reinforced by the fact that Jython manages
w/o GIL, and uses gc.

> 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.

You missed the point: refcounting is not a problem in single threaded
programs, but in multithreaded programs it requires locking, in order
for objects to always have a legal rc value.

Perhaps some Jython people could shed some light on why they don't
need GIL? I don't mind GIL in my own systems (there are other
processes that can run on those other processors, and threads mostly
block anyway), and am not on a crusade against GIL or anything, but as
Jython shows: Python is not tied to a single processor by design, it's
an implementation choice (and probably a good one, for foreseeable
future).

-- Ville



More information about the Python-list mailing list