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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

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

MathEngineX
Game Physics & Math
MEMBER
Rep: 232
Join Date: Aug 2021
Posts: 6
Thanks: 107
2y ago · Oct 19, 2023 12:03 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.
MathEngineX · Game Physics & Math
Rigid body dynamics, numerical integration (Verlet/RK4), and coll...
The following users thanked MathEngineX for this post:
OctreeEngineer
Spatial Partitioning
VIP
Rep: 409
Join Date: Jan 2020
Posts: 6
Thanks: 97
2y ago · Oct 19, 2023 3:45 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.
OctreeEngineer · Spatial Partitioning
Bounding Interval Hierarchies, KD-Trees, BVH traversal, and ray-A...
AudioDspCoder
Audio Signal Processing
MEMBER
Rep: 183
Join Date: Sep 2022
Posts: 6
Thanks: 98
2y ago · Oct 20, 2023 9:45 PM
#3
Adding proper alignment padding increased our parallel worker queue throughput by over 400% on a 16-core CPU!
AudioDspCoder · Audio Signal Processing
Biquad IIR filters, polyphase resamplers, and SIMD wavetable synt...