2.2The Problem: How Incoherence Could Possibly Occur

book pp. 10–11 · ~1 min read

  • actors
  • stale copy
  • the incoherence example

One root cause

The possibility of incoherence arises from exactly one fundamental issue: there exist multiple actors with access to caches and memory. In modern systems those actors are processor cores, DMA engines, and external devices that can read and/or write caches and memory. This primer focuses on cores as the actors, but keep the others in mind — they will matter (coherent DMA returns in Chapter 9).

No second ingredient is required. No reordering, no speculation, no weak memory model — §1.1’s subtleties are a different problem. Perfectly simple, in-order cores are enough to produce incoherence, as the canonical example shows.

The canonical example (Table 2.1)

Initially, memory location A holds 42 — in memory and in both cores’ private caches:

TimeCore C1Core C2
1S1: A = 43;L1: while (A == 42);
2L2: while (A == 42);
3L3: while (A == 42);
4
nLn: while (A == 42);

At time 1, C1 changes A from 42 to 43 in its own cache — remember from §2.1 that the private caches are write-back, so the new value goes no further. C2’s cached copy of A is now stale, and C2’s loop keeps loading that stale 42 from its own cache, hit after hit, forever. C1’s store has simply never been made visible to C2. Step through it:

Core C1S1: A = 43;C1 private cache (write-back)A = 42Core C2L1: while (A == 42);C2 private cacheA = 42main memoryA = 42

1 / 5Initial state

Memory location A holds 42 — in main memory AND in both cores’ private caches. Core C2 is about to run "while (A == 42);" waiting for A to change.

The (only) way out

To prevent incoherence, the system must implement a cache coherence protocol that makes the store from C1 visible to C2. The design and implementation of these protocols — how they detect the write, whom they notify, what state they track — is the main topic of chapters 6–9. Everything there is, at heart, a machine for ending exactly this kind of stale-copy standoff.

Check yourself

1.What is the ONE fundamental issue that makes incoherence possible at all?

2.In the Table 2.1 example, why does Core C2 spin forever even though C1 already stored A = 43?

3.Which of these count as 'actors' that can cause incoherence in modern systems?

4.Predict: with an invalidate-style coherence protocol in place, what happens to C2's while loop after C1's store?

4 questions