[libcxx-commits] [libcxx] 2d1bc4f - [libc++] Fix usage of constructive interference when we meant destructive (#208804)
via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 14 04:51:10 PDT 2026
Author: Louis Dionne
Date: 2026-07-14T07:51:06-04:00
New Revision: 2d1bc4fc5d00d6c96307d5375d7259011509faf3
URL: https://github.com/llvm/llvm-project/commit/2d1bc4fc5d00d6c96307d5375d7259011509faf3
DIFF: https://github.com/llvm/llvm-project/commit/2d1bc4fc5d00d6c96307d5375d7259011509faf3.diff
LOG: [libc++] Fix usage of constructive interference when we meant destructive (#208804)
We maintain a contention table to implement atomic wait/notify inside
atomic.cpp. Entries in that table are padded to avoid false sharing,
since they are expected to be accessed from multiple threads
concurrently.
However, we used std::hardware_constructive_interference_size for that,
when in reality std::hardware_destructive_interference_size is the one
we need. The semantics of constructive interference are to promote true
sharing for data that should stay colocated, while destructive
interference is to prevent false sharing.
Note that on platforms such as macOS arm64, destructive interference
size is larger than constructive interference size, which means that
this patch may regress the size of the dylib on some platforms. However,
that is required for performance purposes.
Fixes #208305
Added:
Modified:
libcxx/src/atomic.cpp
Removed:
################################################################################
diff --git a/libcxx/src/atomic.cpp b/libcxx/src/atomic.cpp
index 25c146d5d51f7..15e0692100341 100644
--- a/libcxx/src/atomic.cpp
+++ b/libcxx/src/atomic.cpp
@@ -425,7 +425,7 @@ static constexpr hash<void const*> __contention_hasher;
// cache line, we would end up in a "false-sharing" situation. However, in practice, it would require
// both native and non-native atomics to be used concurrently, and to fall in the same bucket, which
// is expected to be unlikely.
-struct alignas(std::hardware_constructive_interference_size) /* aim to avoid false sharing */ __contention_state {
+struct alignas(std::hardware_destructive_interference_size) /* aim to avoid false sharing */ __contention_state {
__cxx_atomic_contention_t __waiter_count_native;
__cxx_atomic_contention_t __waiter_count_global;
__cxx_atomic_contention_t __platform_state;
More information about the libcxx-commits
mailing list