Question about Python threads

Gerhard Häring gerhard.haering at gmx.de
Sat Aug 24 19:56:59 CEST 2002


Armin Steinhoff wrote in comp.lang.python:
> "Stuart D. Gathman" <stuart at bmsi.com> wrote in message news:<wNW89.72956$Pb.3188993 at news2.east.cox.net>...
>> On Wed, 21 Aug 2002 14:18:38 -0400, Mr. Neutron wrote:
>> 
>> > Hello,
>> > If I understand, only one thread can be in the interpreter at any
>> > time.
>> > Now what I don't understand is being in the interpreter at a time part. [...]
> 
>> That is correct.  Current CPython code cannot use more than one CPU.  A C
>> extension can release the GIL and get some parallelism (being careful to
>> reacquire the GIL before calling any Python API) - but that is probably
>> more trouble than its worth.
> 
> Why ??
> 
>> > How does this problem imply to Java as well?
>> 
>> Java threads are mapped to real OS threads (not necessarily one to one).
> 
> Python threads are also real OS threads.
> 
>> Java has no trouble taking advantage of multiple CPUs.
> 
> I believe that's a wrong conclusion :)
> Jave should have the same problems as Python .. if the JAVA VM isn't
> thread safe. Is the JAVA VM thread safe ??

I'll crosspost and ask the experts. How does Java solve the problem of
multiple threads accessing the same objects (that aren't synchronized)
and still keeping the VM in a sane state.

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?

Anybody cares to explain?

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



More information about the Python-list mailing list