From 11e76315877d544604687b8823d75d525b74a781 Mon Sep 17 00:00:00 2001 From: Hannes Roth Date: Thu, 25 Jun 2015 08:44:29 -0700 Subject: [PATCH] (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 --- folly/futures/detail/FSM.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } -- 2.34.1