CAS 原理
我認為位置V 應該包含值A
CAS使用示例(jdk
/**
* Atomically sets to the given value and returns the old value
*
* @param newValue the new value
* @return the previous value
*/ public final int getAndSet(int newValue) {
for (;;) {
int current = get();
if (compareAndSet(current
return current;
}
}
public final boolean compareAndSet(int expect
return unsafe
}
這個方法是
它利用了cpu原語compareAndSet來保障值的唯一性
另
比如 getAndIncrement
[
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27719.html