From: Nathan Bronson Date: Wed, 8 Oct 2014 23:59:27 +0000 (-0700) Subject: fix flaky test from uninitialized std::atomic X-Git-Tag: v0.22.0~291 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bf035046df458d07d274965ab5b09572f0985715;p=folly.git 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 --- 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 = [&]{