test_pr91486_wait_until captured start_steady after launching the async
task whose 1s sleep it waits on.  On a heavily loaded machine the interval
between launching the task and capturing start_steady can be large enough
that the future becomes ready (and wait_until returns) less than 1s after
start_steady, spuriously aborting on the 'elapsed_steady >= 1s' assertion.

Capture start_steady before launching the task so the measured interval
fully contains the task's sleep.

        PR libstdc++/91486

libstdc++-v3/ChangeLog:

        * testsuite/30_threads/async/async.cc (test_pr91486_wait_until):
        Capture start time before launching the async task.

Signed-off-by: Igor Shevlyakov <[email protected]>
---
Testsuite change only; 30_threads/async/async.cc passes with -m32 and -m64 on 
x86_64-pc-linux-gnu.

 libstdc++-v3/testsuite/30_threads/async/async.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/testsuite/30_threads/async/async.cc 
b/libstdc++-v3/testsuite/30_threads/async/async.cc
index b49d2b28b57..0f95fe19a43 100644
--- a/libstdc++-v3/testsuite/30_threads/async/async.cc
+++ b/libstdc++-v3/testsuite/30_threads/async/async.cc
@@ -214,6 +214,10 @@ int float_steady_clock::call_count = 0;
 
 void test_pr91486_wait_until()
 {
+  // Capture the start time before launching the task, so that the
+  // measured interval contains its whole 1s sleep.
+  auto const start_steady = chrono::steady_clock::now();
+
   future<void> f1 = async(launch::async, []() {
       std::this_thread::sleep_for(std::chrono::seconds(1));
     });
@@ -237,7 +241,6 @@ void test_pr91486_wait_until()
   float_steady_clock::time_point const expire = now + wait_time;
   VERIFY( expire > now );
 
-  auto const start_steady = chrono::steady_clock::now();
   auto status __attribute__ ((__unused__)) = f1.wait_until(expire);
   auto const elapsed_steady = chrono::steady_clock::now() - start_steady;
 
-- 
2.55.0

Reply via email to