From 2ddb170320fe286daba3f33dc10e9164d7793831 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Thu, 2 May 2019 14:18:55 -0400 Subject: [PATCH] test/simple_spin: Explicitly wait for futures from async Rather than count on implicitly blocking destruct. Signed-off-by: Adam C. Emerson --- src/test/simple_spin.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/test/simple_spin.cc b/src/test/simple_spin.cc index 81194d84991..4afa670743e 100644 --- a/src/test/simple_spin.cc +++ b/src/test/simple_spin.cc @@ -49,13 +49,14 @@ TEST(SimpleSpin, Test1) // Should also work with pass-by-reference: // (Note that we don't care about cross-threading here as-such.) counter = 0; - async(std::launch::async, []() { + auto f = async(std::launch::async, []() { for(int i = 0; n != i; ++i) { spin_lock(lock); counter++; spin_unlock(lock); } }); + f.wait(); ASSERT_EQ(n, counter); } @@ -111,22 +112,24 @@ TEST(SimpleSpin, spinlock_guard) const auto n = 2000000U; ceph::spinlock sl; - + counter = 0; - async(std::launch::async, [&sl]() { + auto f = async(std::launch::async, [&sl]() { for(int i = 0; n != i; ++i) { std::lock_guard g(sl); counter++; } }); - async(std::launch::async, [&sl]() { + auto g = async(std::launch::async, [&sl]() { for(int i = 0; n != i; ++i) { std::lock_guard g(sl); counter++; } }); + f.wait(); + g.wait(); ASSERT_EQ(2*n, counter); } -- 2.39.5