Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Course
  • Reading Paths
  • Concept Map
  • How to Read the Diagrams
  • Part 0: What Is a Protocol?10
  • Part 1: Timing and Clocking11
  • Part 2: Encoding and Framing12
  • Part 3: Handshakes13
  • Part 4: Flow Control17
  • Part 5: Transactions19
  • Part 6: Concurrency and Performance17
  • Part 7: Ordering13
  • Part 8: Sharing and Arbitration12
  • Part 9: Deadlock and Liveness13
  • Part 10: Reliability and Recovery20
  • Part 11: Bring-Up and Link Management10
  • Part 12: Power8
  • Part 13: Shared State and Coherence9
    • Why Coherence
    • Invalidate or Update
    • MSI, MESI and MOESI
    • Snooping or Directory
    • Ownership and Forwarding
    • Coherence and Consistency
    • I/O Coherence and Cache Maintenance
    • Protocols Compared: Shared State and Coherence
    • Drills: Shared State and Coherence
  • Part 14: Security and Isolation7
  • Part 15: Specifying and Verifying11
  • Part 16: Protocols Dissected17
  • Part 17: Capstones5
  • Part 18: Interview Preparation6
Loading lesson

‹Part 13: Shared State and Coherence
  1. Topics
  2. First Principles of Hardware Protocols
  3. Part 13: Shared State and Coherence
  4. Coherence and Consistency

Part 13 · Shared State and Coherence · Senior (S)

Coherence and Consistency

Coherence guarantees that all cores agree on the order of writes to one address. It says nothing about the order of accesses to different addresses: that is the memory consistency model. Why a fully coherent system can still break a flag-and-data handoff.

On this page

    Note

    Level: Senior (S) · Answers: What if there are several copies of one value?

    Before this: Ownership and Forwarding, Memory Consistency Models

    Core 0 writes data, then sets a flag. Core 1 waits for the flag, then reads the data. The caches are fully coherent: every core eventually sees every write to the flag and to the data in the right order. And yet, on some processors, core 1 sees the flag set and then reads the old data. No coherence rule was broken. A different rule, one coherence never promised, was.

    What does coherence guarantee, and what does it leave to the memory model?

    The obvious answer, and why it breaks

    The obvious belief is that coherent caches make shared memory behave like one memory with no caches, so the handoff must work. Coherence promises much less: for each location separately, all cores see writes in one order, and reads return the latest. It says nothing about how writes to the flag are ordered with writes to the data. A core may make its write to the flag visible before its write to the data (a store buffer draining out of order, a write to a line it owns completing before a miss), and coherence is satisfied for both locations.

    The idea: one address versus all addresses

    Coherence

    Consistency (memory model)

    Concerns

    One location at a time

    The order of accesses to different locations

    Guarantees

    Single writer or many readers; one order of writes per location; reads see the latest

    Which reorderings of loads and stores, across locations, other cores may observe

    Implemented by

    The cache coherence protocol

    The core's pipeline, store buffer and the barrier instructions, on top of coherence

    Programmer's tool

    Nothing to do: it is invisible

    Barriers, acquire and release operations, atomics

    The flag-and-data pattern, as a litmus test (initially data = flag = 0):

    Diagram
    Core 0                 Core 1
    data = 42              while (flag == 0) {}
    flag = 1               r = data
    
    Can r be 0?   TSO (x86): no.   Weak models (Arm, Power, RISC-V RVWMO): yes, without barriers.

    On a weakly ordered processor, a store-store barrier (or a release store) on core 0 and a load-load barrier (or an acquire load) on core 1 restore the intended order. Coherence was working all along; it simply was not the rule that mattered.

    How they fit together

    • Coherence is the foundation: without it, even a single location could have two values, and no memory model could be implemented.

    • The memory model is built on top: the core decides when its loads and stores become visible, and barriers force it to wait (lesson 7.10).

    • Interconnect ordering matters too: barriers must also order transactions in the fabric (lesson 7.5), which is why protocols carry ordering and barrier support.

    How real systems chose

    Architecture

    Memory model on coherent caches

    x86

    Total Store Order: only a later load may pass an earlier store to a different address (fact T16)

    Arm, Power

    Weakly ordered: store buffering, load buffering and message-passing reorderings allowed without barriers (fact T17)

    RISC-V

    RVWMO by default, weak; the Ztso extension gives TSO (fact T17)

    What breaks

    Driver code (illustrative) written and tested on x86 set a descriptor's fields, then its "ready" flag, with plain stores. Ported to an Arm system, the device-facing side occasionally read a ready descriptor with stale fields. Caches were coherent throughout; the missing piece was a release barrier between the field writes and the flag write, which TSO had been providing implicitly.

    Why this matters

    Senior lens. Keep the two words apart: coherence is a per-address guarantee implemented by the cache protocol; consistency is the cross-address ordering contract implemented by cores and barriers on top of it. When a handoff fails on a coherent system, look for a missing barrier, not a coherence bug.

    Interview

    Asked: "Is a coherent system automatically sequentially consistent?"

    Weak answer: Yes, coherence makes all cores see the same memory.

    Strong answer: No. Coherence only orders accesses to one location: per address, one order of writes, and reads see the latest. Sequential consistency is about the order of accesses to different locations. On a coherent weakly ordered machine like Arm, core 0 can write data then a flag and core 1 can see the flag set but the old data, without breaking coherence. The memory model defines which cross-address reorderings are allowed, and barriers or acquire and release operations restore order. x86's TSO forbids that particular reordering; Arm, Power and RISC-V's default model allow it.

    Follow-ups: (1) Which barrier does each core need in the flag example? (2) Why is coherence still required for any memory model?

    Check yourself Does coherence say anything about the order in which core 1 sees writes to two different lines?

    No; that is the memory consistency model's job.

    Check yourself In the litmus test on a TSO machine, can r be 0? Why?

    No: TSO keeps stores in order and loads in order, so if core 1 sees flag = 1 it then sees data = 42.

    Key takeaways

    • Coherence orders accesses to one location; consistency orders accesses across locations.

    • A fully coherent system can still break a flag-and-data handoff under a weak memory model.

    • Barriers and acquire/release operations enforce cross-address order on top of coherence.

    Keep going

    Next: Lesson 13.7, I/O Coherence and Cache Maintenance. Devices that share memory with caches: I/O coherence and cache maintenance.

    Related topics

    • Part 13 overview: Shared State and Coherence

    • Architecture course: Memory Ordering Models

    Previous

    185 / 234

    Next: I/O Coherence and Cache Maintenance

    Up next

    Up nextI/O Coherence and Cache Maintenance

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Why Coherence
    • Invalidate or Update
    • MSI, MESI and MOESI