0
私はjava.util.concurrent.locks.AbstractQueuedSynchronizer
ソースコードを調査しています。unsafe.compareAndSwapInt最初の引数menanig
severalsからは、compareAndSetState
メソッドが呼び出されます。
/**
* Atomically sets synchronization state to the given updated
* value if the current state value equals the expected value.
* This operation has memory semantics of a {@code volatile} read
* and write.
*
* @param expect the expected value
* @param update the new value
* @return {@code true} if successful. False return indicates that the actual
* value was not equal to the expected value.
*/
protected final boolean compareAndSetState(int expect, int update) {
// See below for intrinsics setup to support this
return unsafe.compareAndSwapInt(this, stateOffset, expect, update);
}
パラメータexpect
とupdate
は明白であり、アトミック・パラメータに対応します。ただしthis
はObject(int
ではなく)です。
これは予想とどのように比較されますか?
まだわかりません – gstackoverflow
AbstractQueuedSynchronizerはどのように値を持つことができますか? – gstackoverflow
'AbstractQueuedSynchronizer :: state'フィールドです。オブジェクト自体ではありません。 – glee8e