False sharing¶
Category: Hazards · Status: stub · Lessons: chapter 07, Parallelism
One line: Threads writing unrelated variables that happen to sit on the same CPU cache line keep invalidating each other's cache, slowing down with no logical sharing at all.
Also called: cache line contention.
How it connects¶
- See also: Cache coherence, Contention, NUMA, Profiling concurrent programs
In each language¶
| Rust | crossbeam_utils::CachePadded ↗ pads and aligns a value to the length of a cache line |
| Go | cpu.CacheLinePad ↗ in golang.org/x/sys pads structs to avoid false sharing |
| C++ | std::hardware_destructive_interference_size ↗ (C++17): the minimum offset between two objects to avoid false sharing |
Where to read more¶
- In the books: Concurrency with Modern C++, Rainer Grimm — ch. 13, 'Challenges' → 'False Sharing'
- Reference: Wikipedia: False sharing ↗