J'étudie java.util.concurrent.locks.AbstractQueuedSynchronizer
le code source. De plusieurs endroits invoque la méthode compareAndSetState
.unsafe.compareAndSwapInt premier argument menanig
/**
* 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);
}
Paramètres expect
et update
sont évidents et correspondent aux paramètres Atomics. Mais this
est Object (plutôt que int
).
Comment cela se compare-t-il à attendre?
Je ne sais toujours pas pour moi – gstackoverflow
Comment AbstractQueuedSynchronizer peut avoir de la valeur? – gstackoverflow
C'est le champ 'AbstractQueuedSynchronizer :: state', pas l'objet lui-même. – glee8e