From: Hannes Roth Date: Thu, 25 Jun 2015 15:44:29 +0000 (-0700) Subject: (Wangle) Fix possible race in updating FSM state X-Git-Tag: v0.48.0~11 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=11e76315877d544604687b8823d75d525b74a781;p=folly.git (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 --- diff --git a/folly/futures/detail/FSM.h b/folly/futures/detail/FSM.h index ce77c551..b706ed04 100644 --- a/folly/futures/detail/FSM.h +++ b/folly/futures/detail/FSM.h @@ -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; }