Summary: Storing the new state could be a memory race according to C++ (but wasn't in practice). I only checked GCC though.
Reviewed By: @nbronson
Differential Revision:
D2189287
if (!mutex_.try_lock()) {
mutex_.lock();
}
- if (state_.load(std::memory_order_relaxed) != A) {
+ if (state_.load(std::memory_order_acquire) != A) {
mutex_.unlock();
return false;
}
action();
- state_.store(B, std::memory_order_relaxed);
+ state_.store(B, std::memory_order_release);
mutex_.unlock();
return true;
}