Commit bf035046 authored by Nathan Bronson's avatar Nathan Bronson Committed by Andrii Grynenko

fix flaky test from uninitialized std::atomic

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
parent b6f62e95
...@@ -552,7 +552,7 @@ static void contentionAtWidth(size_t iters, size_t stripes, size_t work, ...@@ -552,7 +552,7 @@ static void contentionAtWidth(size_t iters, size_t stripes, size_t work,
while (!go.load()) { while (!go.load()) {
sched_yield(); sched_yield();
} }
std::atomic<int> localWork; std::atomic<int> localWork(0);
if (spreaderType == SpreaderType::SHARED) { if (spreaderType == SpreaderType::SHARED) {
for (size_t i = iters; i > 0; --i) { for (size_t i = iters; i > 0; --i) {
++*(counters[AccessSpreader<>::current(stripes)]); ++*(counters[AccessSpreader<>::current(stripes)]);
...@@ -604,8 +604,8 @@ static void atomicIncrBaseline(size_t iters, size_t work, ...@@ -604,8 +604,8 @@ static void atomicIncrBaseline(size_t iters, size_t work,
while (!go.load()) { while (!go.load()) {
sched_yield(); sched_yield();
} }
std::atomic<size_t> localCounter; std::atomic<size_t> localCounter(0);
std::atomic<int> localWork; std::atomic<int> localWork(0);
for (size_t i = iters; i > 0; --i) { for (size_t i = iters; i > 0; --i) {
localCounter++; localCounter++;
for (size_t j = work; j > 0; --j) { for (size_t j = work; j > 0; --j) {
......
...@@ -261,7 +261,7 @@ TEST(LifoSem, multi_try_wait) { ...@@ -261,7 +261,7 @@ TEST(LifoSem, multi_try_wait) {
} }
}; };
std::atomic<bool> consumer_stop; DeterministicAtomic<bool> consumer_stop(false);
int consumed = 0; int consumed = 0;
auto consumer = [&]{ auto consumer = [&]{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment