silicon atlasTHE HARDWARE REFERENCE
العربية
Reference/Memory & storage
Memory & storage

False sharing & cache-line contention

Independent variables can still share the same coherence unit.

Two threads can slow each other down while writing different variables.
Thread A

Writes its own word.

LIVE EXPERIMENT

Make a cache miss

Runs on your device
BYTE ADDRESS0Block 0 → Set 0MISS
SET 0tag 0
SET 1·
SET 2·
SET 3·
SET 4·
SET 5·
SET 6·
SET 7·
Accesses1
Hit rate0%
Bytes fetched64
Select any access above, or step through the trace.

A cache fetches a whole line. Locality reuses it; conflicting mappings can evict useful data even before total capacity is exhausted.

What this model includes

One read-only cache, 64-byte lines, LRU replacement, eight total lines, eight-byte elements, 32 accesses. No prefetching or multilevel effects.

FOLLOW THE MECHANISM

What happens inside

1

See the unit of ownership

Coherence usually tracks cache lines, not individual source variables. If two threads repeatedly write different words in the same line, ownership can bounce between cores. This is false sharing. Actual sharing writes the same data; read-only sharing does not create the same invalidation pattern.

2

Change the layout deliberately

Separating frequently written per-thread data can reduce ownership traffic. Padding and alignment help when they match the line and allocation behavior, but enlarge memory use and may hurt cache locality. Aggregating local counters later can avoid a hot shared update.

PUT IT TO WORK

What this means for your code

Low-level engineer

Confirm line contention with appropriate counters or tools. Allocation alignment and object stride both matter.

Software developer

Prefer local accumulators with a final merge for counters and reductions. Measure before padding every object.

GO TO THE SOURCE

Read the actual specifications

These references supply the underlying contracts and implementation details. The diagrams here are simplified teaching models.

Intel · False sharingIntel

Keep following the connection

Understood the idea? Keep a note of your progress.