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
Unsafe.getIntVolatile()
called instead of
Unsafe.getInt()
here?
I am basically familiar with memory models, memory barriers etc., but, perhaps
I don't see any something important.
*getIntVolatile* means here: ensure the order of execution: (1) -> (2)
It looks something like:
curr = read();
acquire();
CAS operation
Obviously, acquire() depends on CPU, for example on x86 it is empty, on ARM it
is a memory barrier, etc.
My question/misunderstanding:
For my eye the order is ensured by data dependency between read of *(ptr +
offset)* and *CAS* operation on it. So, I don't see a reason to worry about
memory (re)ordering.
--
You received this message because you are subscribed to the Google Groups
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.