[PATCH] testsuite: semaphore/try_acquire_until: reorder clock::now calls

Alexandre Oliva oliva@adacore.com
Wed Apr 29 01:49:07 GMT 2026


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.

Regstrapped on x86_64-linux-gnu.  Also tested on ppc-vx7r2 with gcc-15,
with an analogous patch for try_acquire_posix.cc.  Ok to install?


for  libstdc++-v3/ChangeLog

	* testsuite/30_threads/semaphore/try_acquire_until.cc
	(test01): Reorder calls.
---
 .../30_threads/semaphore/try_acquire_until.cc      |    2 +-
 1 file changed, 1 insertion(+), 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 44b2b90431a41..dea8c53a5a02f 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,8 @@ void test01()
   }
 
   {
-    auto const at = std::chrono::system_clock::now() + dur;
     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 );


-- 
Alexandre Oliva, happy hacker            https://blog.lx.oliva.nom.br/
Free Software Activist     FSFLA co-founder     GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity.
Excluding neuro-others for not behaving ""normal"" is *not* inclusive!


More information about the Libstdc++ mailing list