2017-03-14 10 views
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); 
} 

パラメータexpectupdateは明白であり、アトミック・パラメータに対応します。ただしthisはObject(intではなく)です。
これは予想とどのように比較されますか?

答えて

0

これは、フィールドstateがCASで編集されるインスタンスです。値はそのフィールドに格納されます。インスタンスオフセットペアは、Field::set,Field::getまたはMethod::invokeを使用するときにインスタンスを指定する必要があるように、フィールド記述子をメモリアドレスに変換する方法です。

ところで、これらの日クラスソースはopenjdk's mercury repositoryからオンラインで入手可能です。

+0

まだわかりません – gstackoverflow

+0

AbstractQueuedSynchronizerはどのように値を持つことができますか? – gstackoverflow

+0

'AbstractQueuedSynchronizer :: state'フィールドです。オブジェクト自体ではありません。 – glee8e

関連する問題