fix flaky test from uninitialized std::atomic
authorNathan Bronson <ngbronson@fb.com>
Wed, 8 Oct 2014 23:59:27 +0000 (16:59 -0700)
committerAndrii Grynenko <andrii@fb.com>
Wed, 15 Oct 2014 00:56:03 +0000 (17:56 -0700)
Summary:
std::atomic<bool> default constructor doesn't initialize it to
false, so the flag to end the LifoSem.multi_try_wait test was sometimes
set too early.  This diff fixes that, makes the test more deterministic,
and also fixes a couple of other benign uninitialized values (so that
they won't be used as prototypes for places where it does matter).

Test Plan: unit tests

Reviewed By: mpawlowski@fb.com

Subscribers: njormrod, lovro

FB internal diff: D1604508

Tasks: 5336837

folly/test/CacheLocalityTest.cpp
folly/test/LifoSemTests.cpp

index b3f7207d7ea7bb3b933535e9dfef9f1572c7f52b..82026c29d45a96acea3fd38a0cb62aa022cd39f3 100644 (file)
@@ -552,7 +552,7 @@ static void contentionAtWidth(size_t iters, size_t stripes, size_t work,
       while (!go.load()) {
         sched_yield();
       }
-      std::atomic<int> localWork;
+      std::atomic<int> localWork(0);
       if (spreaderType == SpreaderType::SHARED) {
         for (size_t i = iters; i > 0; --i) {
           ++*(counters[AccessSpreader<>::current(stripes)]);
@@ -604,8 +604,8 @@ static void atomicIncrBaseline(size_t iters, size_t work,
       while (!go.load()) {
         sched_yield();
       }
-      std::atomic<size_t> localCounter;
-      std::atomic<int> localWork;
+      std::atomic<size_t> localCounter(0);
+      std::atomic<int> localWork(0);
       for (size_t i = iters; i > 0; --i) {
         localCounter++;
         for (size_t j = work; j > 0; --j) {
index e3de16b7662d20ed5e9a54be90e32d2ecc0bcf39..7d034211827ae7065965f987b1d56c1cebeb5952 100644 (file)
@@ -261,7 +261,7 @@ TEST(LifoSem, multi_try_wait) {
     }
   };
 
-  std::atomic<bool> consumer_stop;
+  DeterministicAtomic<bool> consumer_stop(false);
   int consumed = 0;
 
   auto consumer = [&]{