Question about Python threads

Artur Biesiadowski abies at pg.gda.pl
Thu Aug 29 11:27:58 EDT 2002


Chris Bailey wrote:

>>Anyway, in java, you can modify anything from as many threads as you
>>like. Of course, without synchronization, effect of operation is
>>unexpected - but result will be legal. This means that if two threads
>>modify int field =1 by adding 1 to it, you can get 3 or 2 as a result,
>>but not 1, -1 or JVM crash.
> 
> 
> Correct. As is the case in any language. If there is no locking on data and
> multiple threads are acting on it, there is no guarantee in which order the
> data manipulation will occurr.

Difference is that in java it is defined what can happen. In C for 
example, there is a chance that you can observe half-update for 
non-aligned int32. In java you are sure it will not happen (it not 
important that it will be probably implemented by aligning all integers 
if needed :)

> Now you are into the world of supposition. You have started talking about
> how a given JVM is implimented, and this has nothing what so-ever to do with
> the JVM specification, or the Java language. 
[...]
> This is also completely irrelevant to a discussion of Java locking/memory
> model.

Originally thread was about refcounts and that Python _implementation_ 
can crash in presence of multiple threads. I have explained how java 
_implementations_ avoid that problem. Original poster has not cared 
about specs - he was interested in implementation. I probably should 
write less and do not mention spec at all.

> Anytime a JVM crashes running pure Java code (without JNI) is a JVM bug.

 From certain point of view, yes. I was talking about crashed in AWT 
code. If you look at java platform as monolitic library, then yes, it is 
JVM bug. But AWT crashes are specific library bugs, caused often by 
underlaying operating system deficiencies.

Does it fit defintion of 'pure Java code' ? There is a JNI under the 
hood - so no. On the other hand, it is part of core, and there is JNI 
almost everywhere, even in basic java.lang.Object code - so probably yes.
This is a gray area for me. I certainly agree that it is a bug, but this 
'pure java code' distinction is unclear IMHO.

In context of original post - there is nothing that could crash 
'theoretical' JVM (interaction of threads etc). But current 
implementation have buggy native libs, so...


Artur




More information about the Python-list mailing list