https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114953

            Bug ID: 114953
           Summary: libstdc++'s 30_threads/semaphore/try_acquire_posix.cc
                    can sometimes fail (while running under qemu)
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: testsuite-fail
          Severity: normal
          Priority: P3
         Component: testsuite
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

The testcase has:
```
  auto const dur = 250ms;
...
    auto const at = std::chrono::system_clock::now() + dur;
    auto const t0 = std::chrono::steady_clock::now();
    VERIFY( !s._M_try_acquire_until(at) );
    auto const diff = std::chrono::steady_clock::now() - t0;
    VERIFY( diff >= dur );
```

So the difference here might be less than 250ms because it might be that t0
might have been a few (one or two?) microseconds after at was set.
This testcase failed for me with -std=c++26 but passed for -std=c++20 while
running in the testsuite but on a semi-loaded system and running under qemu. So
it just happened to hit the failure in that case. I suspect it could fail while
not running under qemu but with a heavy load on the system and it just happens
to be time sliced out between the 2 calls to now().

Maybe there should only 1 call to now before until so you don't run into
spurious failure like this.

Reply via email to