Fixes RCU test cases error (loads should use Consume ordering)
authorPeizhao Ou <peizhaoo@uci.edu>
Tue, 13 Feb 2018 19:07:52 +0000 (11:07 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Tue, 13 Feb 2018 19:07:52 +0000 (11:07 -0800)
folly/stress-test/stress-parallel-folly-sync.cpp
folly/stress-test/stress-sequential-folly-sync.cpp

index af820c7..c1b6ed5 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);
index 9622230..5e39e42 100644 (file)
@@ -44,7 +44,7 @@ protected:
     size_t sum = 1;
     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);
     }
     EXPECT_EQ(sum, 1);
@@ -56,16 +56,16 @@ protected:
       for (size_t count = 0; count < pass_count; count++) {
         for (int i = 0; i < 100; ++i) {
           if (i < write_percentage) {
-            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;
           } else {
             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);
           }
         }
@@ -80,15 +80,15 @@ protected:
       for (size_t count = 0; count < pass_count; count++) {
         for (int i = 0; i < 100; ++i) {
           if (i < write_percentage) {
-            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);
           } else {
             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);
           }
         }