Fixes RCU test cases error (loads should use Consume ordering)
[folly.git] / folly / stress-test / stress-parallel-folly-sync.cpp
index af820c7f4e1aea498566f5d919403fa6e1b97481..c1b6ed573e31171dfe4ea4e1914c472cfca7ea13 100644 (file)
@@ -56,11 +56,11 @@ protected:
 
   static void run_rcu_writer_sync() {
     while (rcu_readers_num.load(std::memory_order_acquire) > 0) {
-      auto *old_data = rcu_data.load(std::memory_order_relaxed);
+      auto *old_data = rcu_data.load(std::memory_order_consume);
       auto *new_data = new RcuData(*old_data);
       new_data->d1++;
       new_data->d2++;
-      rcu_data.store(new_data, std::memory_order_relaxed);
+      rcu_data.store(new_data, std::memory_order_release);
       folly::synchronize_rcu();
       delete old_data;
       std::this_thread::sleep_for(
@@ -70,11 +70,11 @@ protected:
 
   static void run_rcu_writer_no_sync() {
     while (rcu_readers_num.load(std::memory_order_acquire) > 0) {
-      auto *old_data = rcu_data.load(std::memory_order_relaxed);
+      auto *old_data = rcu_data.load(std::memory_order_consume);
       auto *new_data = new RcuData(*old_data);
       new_data->d1++;
       new_data->d2++;
-      rcu_data.store(new_data, std::memory_order_relaxed);
+      rcu_data.store(new_data, std::memory_order_release);
       folly::rcu_retire(old_data);
       std::this_thread::sleep_for(
           std::chrono::milliseconds(s_nRcuWriterFrequency));
@@ -85,7 +85,7 @@ protected:
     size_t sum = 0;
     for (size_t count = 0; count < pass_count; count++) {
       folly::rcu_reader g;
-      auto *data = rcu_data.load(std::memory_order_relaxed);
+      auto *data = rcu_data.load(std::memory_order_consume);
       sum += (data->d1 + data->d2);
     }
     rcu_readers_num.fetch_sub(1, std::memory_order_release);