[libcxx-commits] [libcxx] [libc++] Improve performance of std::atomic_flag on Windows (PR #163524)
Roger Sanders via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 15 15:08:24 PDT 2025
RogerSanders wrote:
> I observe that just substituting `WaitOnAddress` where other platforms used FUTEX will work, but that does not take advantage of multiple sizes supported by `WaitOnAddress`.
>
> `WaitOnAddress` can wait on 1, 2, 4, or 8 bytes in both x86-64 and 32-bit x86, so can implement most `atomic<T>::wait` operations directly.
>
> Though taking advantage of varying sizes seems complicated, so maybe not worth doing.
Sorry, missed your comment earlier. That's a good point, although we'd still need a loop above WaitOnAddress checking the value, since as per C++20 the wait functions on atomics must not unblock spuriously, while WaitOnAddress can, so it's not quite a direct implementation, but still pretty close.
I'd personally put this in the realm of a possible future enhancement under a different job though. 99% of the value is obtained by this simpler change, although it is a pity std::atomic_flag in particular still uses a surrogate address rather than using the actual address directly. Addressing this would involve an ABI change though, whereas this change is fully ABI compatible with the existing implementation.
https://github.com/llvm/llvm-project/pull/163524
More information about the libcxx-commits
mailing list