A simple answer would be that the field is treated by the method as a
volatile, and the code is simply staying consistent with that notion. Is an
optimization possible here? Possibly and Probably. But does it matter?
No. The source code involved is not performance critical, and is not worth
Hello
it is an implementation from sun.misc.Unsafe.
public final int getAndAddInt(Object ptr, long offset, int value) {
int curr;
do {
curr = this.getIntVolatile(ptr, offset); (1)
} while(!this.compareAndSwapInt(ptr, offset, curr, curr + value)); (2)
return curr;}
Why there is