Home / Forums / Understanding False Sharing in Multi-Threaded C++ Data Structures [Part 3]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Understanding False Sharing in Multi-Threaded C++ Data Structures [Part 3]

CleanCppGuru
Software Architecture
MEMBER
Rep: 302
Join Date: Feb 2021
Posts: 6
Thanks: 91
5y ago · Feb 13, 2021 6:43 PM
#1
False sharing occurs when two independent threads modify variables that reside on the exact same 64-byte CPU cache line. Even though the variables are distinct, the hardware cache coherence protocol constantly invalidates cache lines across cores.
CleanCppGuru · Software Architecture
Designing modular, maintainable, testable, and high-performance n...
The following users thanked CleanCppGuru for this post:
RAII_Guardian
Modern C++ Architect
MEMBER
Rep: 51
Join Date: May 2024
Posts: 6
Thanks: 22
5y ago · Feb 13, 2021 11:26 PM
#2
Use alignas(std::hardware_destructive_interference_size) on multi-threaded shared counters or per-thread state structures to ensure they occupy separate cache lines.
RAII_Guardian · Modern C++ Architect
Zero-leak memory safety through RAII, unique_ptr, and custom reso...
BitTwiddler
Bitwise Algorithms
VIP
Rep: 79
Join Date: Jan 2020
Posts: 6
Thanks: 71
5y ago · Feb 15, 2021 3:26 AM
#3
Adding proper alignment padding increased our parallel worker queue throughput by over 400% on a 16-core CPU!
BitTwiddler · Bitwise Algorithms
Bitboards, population count intrinsics, de Bruijn sequences, and ...