From 2cf72093b1b8c52ef14435ced23eca01baf311fe Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Fri, 21 Apr 2023 10:44:06 -0700 Subject: [PATCH] Update test to spin until the container is non-empty --- test/cfoa/constructor_tests.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/cfoa/constructor_tests.cpp b/test/cfoa/constructor_tests.cpp index 4d92d6b5..39fbc76a 100644 --- a/test/cfoa/constructor_tests.cpp +++ b/test/cfoa/constructor_tests.cpp @@ -534,22 +534,25 @@ namespace { { map_type x(0, hasher(1), key_equal(2), allocator_type{}); - auto f = [&x, &values, &m, &cv, &ready] { + std::atomic_uint num_transfers{0}; + + std::thread t1([&x, &values] { + for (auto const& val : values) { + x.insert(val); + } + }); + + std::thread t2([&x, &m, &cv, &ready] { + while (x.empty()) { + std::this_thread::yield(); + } + { std::lock_guard guard(m); ready = true; } cv.notify_all(); - - for (auto const& val : values) { - x.insert(val); - } - }; - - std::atomic_uint num_transfers{0}; - - std::thread t1(f); - std::thread t2(f); + }); thread_runner( values, [&x, &reference_map, &num_transfers, rg, &m, &ready, &cv](