Ugo Cei wrote:

Sylvain Wallez wrote:

I was just looking in the VM spec if a increment operation on an integer is atomic or not. My opinion it has to be in the case of class members as the increment is surrounded by getfield/putfield instructions.


Accessing an "int" is atomic. Accessing a "long" is not. This is all from memory, which might fail, of course ... so let me see if I can dig up a reference...

There! Doug Lea, "Concurrent Programming in Java", p. 63:

"The Java language specification allows access and storage of [variables of type double and long] (but not those of other scalar types) to be non-atomic."


Agree for *variables*. Here, we have a class member, which has to be loaded, then incremented, then stored.

So as Bertrand, I stay on the safe side and synchronize.

Sylvain

--
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }



Reply via email to