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

            Bug ID: 118402
           Summary: std::barrier doesn't use futex directly
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
            Blocks: 88322
  Target Milestone: ---

Split out from PR 99277


The wait/notify synchronization in std::barrier is done on a 1-byte enum, which
means it has to use a proxy wait inside std::atomic::wait instead of using the
atomic as a futex directly.

If we increased it to an int (or just use std::atomic_signed_lock_free, which
uses int for linux) then the syncrhonization would be more efficient. We might
not even lose any space efficiency, since the enum has to be aligned for atomic
ops and there's tail padding after it anyway.

We could still use the same range of values as the 1-byte type, just store it
as an int.

We could also consider an adaptive implementation which doesn't use a tree
barrier for small values, which could avoid the need for dynamic allocation for
an array of tickets. A barrier with a small count probably isn't going to be
contended by huge numbers of threads, because there aren't a huge number of
waiters.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88322
[Bug 88322] Implement C++20 library features.

Reply via email to