GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

libstdc++: Use hardware_destructive_interference_size in atomic.cc.

The libstdc++ now uses `std::hardware_destructive_interference_size` for aligning atomic variables to improve performance.

The libstdc++ now uses std::hardware_destructive_interference_size to align atomic variables in atomic.cc. This improves performance by reducing false sharing between threads. The code was moved from a header into the library, making it possible to use std::hardware_destructive_interference_size directly.

In Details

This commit removes __waitable_state::_S_align and uses std::hardware_destructive_interference_size for aligning __waitable_state::_M_waiters and __waitable_state::_M_ver in src/c++20/atomic.cc. This is done to avoid false sharing. Search snippets should focus on std::hardware_destructive_interference_size and false sharing.

For Context

False sharing occurs when multiple threads access different data items that happen to reside within the same cache line. Even if the threads don't access the same variables, modifications by one thread can invalidate the cache line for other threads, leading to performance degradation. std::hardware_destructive_interference_size is a C++17 feature that provides the recommended alignment to avoid false sharing. This commit uses it to align atomic variables, which are commonly used for inter-thread communication, thereby reducing the likelihood of false sharing and improving performance.

Filed Under: libstdc++C++atomicperformance