Commit 11e76315 authored by Hannes Roth's avatar Hannes Roth Committed by Sara Golemon

(Wangle) Fix possible race in updating FSM state

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
parent e51d8547
......@@ -55,12 +55,12 @@ public:
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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment