On Fri, 23 Sep 2005 16:26:05 +0100, "Chris Uppal"
<> wrote or quoted :
>No. Not by definition; though I suppose it might happen to be "atomic" on some
>particular combinations of machine architecture and code-generation strategy.
Consider this snippet of code:
public class VolatileTest
{
private static volatile long key=0;
public static void main ( String[] args )
{
key++;
}
}
if you compile it and disassemble it with javap -c VolatileTest
you will see the ++ increment is implemented with four JVM
instructions:
getstatic #2; //Field key:J
lconst_1
ladd
putstatic #2; //Field key:J
That means it is most certainly not atomic.
However, on an Intel machine an optimising compiler or AOT compiler
might coalesce that like this:
inc key[ebx]
which would be atomic at least on a single CPU machine.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.