Allow stealing pointer bits
[folly.git] / folly / experimental / hazptr / test / HazptrTest.cpp
index d8ca18dacf7ad406bab73c24aeadbd07d3b021b6..301aaa805d53cf53f75ac4497d674f6af0452560 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <folly/experimental/hazptr/debug.h>
 #include <folly/experimental/hazptr/example/LockFreeLIFO.h>
+#include <folly/experimental/hazptr/example/MWMRSet.h>
 #include <folly/experimental/hazptr/example/SWMRList.h>
 #include <folly/experimental/hazptr/example/WideCAS.h>
 #include <folly/experimental/hazptr/hazptr.h>
@@ -224,6 +225,36 @@ TEST_F(HazptrTest, SWMRLIST) {
   }
 }
 
+TEST_F(HazptrTest, MWMRSet) {
+  using T = uint64_t;
+
+  CHECK_GT(FLAGS_num_threads, 0);
+  for (int i = 0; i < FLAGS_num_reps; ++i) {
+    DEBUG_PRINT("========== start of rep scope");
+    MWMRListSet<T> s;
+    std::vector<std::thread> threads(FLAGS_num_threads);
+    for (int tid = 0; tid < FLAGS_num_threads; ++tid) {
+      threads[tid] = std::thread([&s, tid]() {
+        for (int j = tid; j < FLAGS_num_ops; j += FLAGS_num_threads) {
+          s.contains(j);
+          s.add(j);
+          s.remove(j);
+        }
+      });
+    }
+    for (int j = 0; j < 10; ++j) {
+      s.add(j);
+    }
+    for (int j = 0; j < 10; ++j) {
+      s.remove(j);
+    }
+    for (auto& t : threads) {
+      t.join();
+    }
+    DEBUG_PRINT("========== end of rep scope");
+  }
+}
+
 TEST_F(HazptrTest, WIDECAS) {
   WideCAS s;
   std::string u = "";