diff --git a/libstdc++-v3/testsuite/30_threads/async/async.cc b/libstdc++-v3/testsuite/30_threads/async/async.cc index 3b157ed9c56800f760280784849bcf5d068e1234..2474d318d7b1be670578f2ed0e5c63b7ed610548 100644 --- a/libstdc++-v3/testsuite/30_threads/async/async.cc +++ b/libstdc++-v3/testsuite/30_threads/async/async.cc @@ -173,7 +173,7 @@ void test_pr91486_wait_for() std::chrono::duration<float> const wait_time = std::chrono::seconds(1); auto const start_steady = chrono::steady_clock::now(); - auto status = f1.wait_for(wait_time); + auto status __attribute__ ((__unused__)) = f1.wait_for(wait_time); auto const elapsed_steady = chrono::steady_clock::now() - start_steady; VERIFY( elapsed_steady >= std::chrono::seconds(1) ); @@ -209,7 +209,7 @@ struct float_steady_clock } }; -chrono::steady_clock::time_point float_steady_clock::epoch = chrono::steady_clock::now(); +chrono::steady_clock::time_point float_steady_clock::epoch; int float_steady_clock::call_count = 0; void test_pr91486_wait_until() @@ -218,6 +218,19 @@ void test_pr91486_wait_until() std::this_thread::sleep_for(std::chrono::seconds(1)); }); + // When we don't _GLIBCXX_HAVE_LINUX_FUTEX, we use + // condition_variables, whose wait_until converts times using + // deltas, and if too much time has elapsed since we set the epoch + // during program initialization, say if the other tests took over + // 8s and we're unlucky with the numbers, we may lose enough + // precision from the 1s delta that we don't sleep until the + // deadline, and then we may loop more times than expected. Each + // iteration will recompute the wait time from deadline - + // float_steady_clock::now(), and each such computation will bump + // float_steady_clock::call_count, so the call_count check below + // will fail spuriously. Setting the epoch just before running this + // test makes this failure mode far less likely. + float_steady_clock::epoch = chrono::steady_clock::now(); float_steady_clock::time_point const now = float_steady_clock::now(); std::chrono::duration<float> const wait_time = std::chrono::seconds(1); @@ -225,7 +238,7 @@ void test_pr91486_wait_until() VERIFY( expire > now ); auto const start_steady = chrono::steady_clock::now(); - auto status = f1.wait_until(expire); + auto status __attribute__ ((__unused__)) = f1.wait_until(expire); auto const elapsed_steady = chrono::steady_clock::now() - start_steady; // This checks that we didn't come back too soon