ミューテックスの例があります。CurrentValue- のメンバーClass
int Class::NextValue()
{
mutex.lock();
++CurrentValue;
++CurrentValue;
int localValue = CurrentValue;
mutex.unlock();
return localValue;
}
が使用される理由がわかりませんlocalValue。次のコードは正しく動作しませんか?
...
mutex.unlock();
return CurrentValue;
whenreturnがアトミックでない場合、CurrentValueコピー コンストラクター中に変更される可能性があります。しかし、最初のコード例では、localValue?