Skip to content

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

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