[gcc(refs/users/aoliva/heads/testme)] testsuite: semaphore/try_acquire_until: reorder clock::now calls
Alexandre Oliva
aoliva@gcc.gnu.org
Thu Apr 30 04:44:44 GMT 2026
https://gcc.gnu.org/g:de57a2518b877444b03aecd389acfcc911c6e06b
commit de57a2518b877444b03aecd389acfcc911c6e06b
Author: Alexandre Oliva <oliva@adacore.com>
Date: Wed Apr 29 22:27:00 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