Learning path

Full curriculum

Full curriculum

Arrows go from each prerequisite to the units that depend on it. Hover or focus a unit to highlight its path.

Unit content

False sharing and cache-line contention

Two threads can contend through the cache-coherence system even when they never access the same variable.

Suppose a and b are independent counters stored on the same cache line. Core A repeatedly writes a while core B repeatedly writes b.

Because coherence tracks the whole cache line, each write can require ownership of that line. The line then ping-pongs between cores even though the logical variables are unrelated. This is false sharing.

False sharing preserves correctness but can destroy scaling. A sequential benchmark may look normal while adding threads makes the program slower because coherence traffic grows.

Typical remedies are to give independently written data separate cache lines, partition arrays so workers write disjoint contiguous regions, or restructure accumulation so each worker updates private state and combines results later.

Padding every object blindly wastes cache capacity. The goal is narrower: keep frequently written data owned by different workers from occupying the same coherence unit.

False sharing is a reminder that the physical sharing unit can be larger than the program's logical variable.