On Apr 29, 2026, Jonathan Wakely <[email protected]> wrote:
> On Wed, 29 Apr 2026 at 02:51, Alexandre Oliva <[email protected]> wrote:
>>
>>
>> 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?
> OK for trunk (and branches if you want, but wait until after 16.1 is
> released).
Thanks, I'm going for trunk only, at least for now.
In internal review, Olivier Hainque suggested a comment justifying the
asymmetry, so here's what I plan to check in, barring any objections:
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.
---
.../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 44b2b90431a41..a22799d88508a 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 );
--
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!