]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: semaphore/try_acquire_until: reorder clock::now calls
authorAlexandre Oliva <oliva@adacore.com>
Sat, 2 May 2026 06:28:07 +0000 (03:28 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Sat, 2 May 2026 06:28:07 +0000 (03:28 -0300)
Clock calls on VxWorks are slow, so the odds that the consecutive
calls of *clock::now() will yield a different result are not
negligible.  Reordering the calls avoids false positives.

for  libstdc++-v3/ChangeLog

* testsuite/30_threads/semaphore/try_acquire_until.cc
(test01): Reorder calls.

libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc

index 44b2b90431a41af7d5524c09b4a17eefcc137174..a22799d88508a16fc5d83546ac9276496413f7e7 100644 (file)
@@ -43,8 +43,11 @@ void test01()
   }
 
   {
-    auto const at = std::chrono::system_clock::now() + dur;
+    // Set the base time T0 first, so that even if there's a delay before the
+    // deadline AT is computed, it won't shrink the measured DIFF to the point
+    // of making it seem shorter than the required wait DURation.
     auto const t0 = std::chrono::steady_clock::now();
+    auto const at = std::chrono::system_clock::now() + dur;
     VERIFY( !s.try_acquire_until(at) );
     auto const diff = std::chrono::steady_clock::now() - t0;
     VERIFY( diff >= dur );