[gcc r17-272] testsuite: semaphore/try_acquire_until: reorder clock::now calls

Alexandre Oliva aoliva@gcc.gnu.org
Sat May 2 06:35:45 GMT 2026


https://gcc.gnu.org/g:dcc21c5517eeaec3d41cbf7790e833f24a1f8c87

commit r17-272-gdcc21c5517eeaec3d41cbf7790e833f24a1f8c87
Author: Alexandre Oliva <oliva@adacore.com>
Date:   Sat May 2 03:28:07 2026 -0300

    testsuite: semaphore/try_acquire_until: reorder clock::now calls
    
    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.

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

diff --git a/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc b/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc
index 44b2b90431a4..a22799d88508 100644
--- a/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc
+++ b/libstdc++-v3/testsuite/30_threads/semaphore/try_acquire_until.cc
@@ -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 );


More information about the Libstdc++-cvs mailing list