From bf035046df458d07d274965ab5b09572f0985715 Mon Sep 17 00:00:00 2001 From: Nathan Bronson Date: Wed, 8 Oct 2014 16:59:27 -0700 Subject: [PATCH] fix flaky test from uninitialized std::atomic Summary: std::atomic 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 | 6 +++--- folly/test/LifoSemTests.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/folly/test/CacheLocalityTest.cpp b/folly/test/CacheLocalityTest.cpp index b3f7207d..82026c29 100644 --- a/folly/test/CacheLocalityTest.cpp +++ b/folly/test/CacheLocalityTest.cpp @@ -552,7 +552,7 @@ static void contentionAtWidth(size_t iters, size_t stripes, size_t work, while (!go.load()) { sched_yield(); } - std::atomic localWork; + std::atomic 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 localCounter; - std::atomic localWork; + std::atomic localCounter(0); + std::atomic localWork(0); for (size_t i = iters; i > 0; --i) { localCounter++; for (size_t j = work; j > 0; --j) { diff --git a/folly/test/LifoSemTests.cpp b/folly/test/LifoSemTests.cpp index e3de16b7..7d034211 100644 --- a/folly/test/LifoSemTests.cpp +++ b/folly/test/LifoSemTests.cpp @@ -261,7 +261,7 @@ TEST(LifoSem, multi_try_wait) { } }; - std::atomic consumer_stop; + DeterministicAtomic consumer_stop(false); int consumed = 0; auto consumer = [&]{ -- 2.34.1