Fix a data race found by TSAN in folly::fibers::Baton
authorMartin Martin <mcm@fb.com>
Thu, 9 Jun 2016 18:53:14 +0000 (11:53 -0700)
committerFacebook Github Bot 1 <facebook-github-bot-1-bot@fb.com>
Thu, 9 Jun 2016 19:08:37 +0000 (12:08 -0700)
Summary: Fix a data race found by TSAN in folly::fibers::Baton by changing a memory_order_relaxed to memory_order_acquire.  Nathan Bronson says that TSAN is correct and the C++ memory model requires _acquire here.

Reviewed By: andriigrynenko

Differential Revision: D3412519

fbshipit-source-id: bd0043b41d145e689a97fc7ef47aa6e116ea9194

folly/fibers/Baton.cpp

index 7161f9fb97f8a49e4e763e842ce6bf97080f1a57..5f5a104c079d0068e94d62cbe7dffc822c15cb6c 100644 (file)
@@ -58,7 +58,7 @@ void Baton::waitThread() {
           waitingFiber_.compare_exchange_strong(fiber, THREAD_WAITING))) {
     do {
       folly::detail::MemoryIdler::futexWait(futex_.futex, THREAD_WAITING);
-      fiber = waitingFiber_.load(std::memory_order_relaxed);
+      fiber = waitingFiber_.load(std::memory_order_acquire);
     } while (fiber == THREAD_WAITING);
   }