Advanced Topic 38 of 51 Computer Architecture & Logic
Cache Coherence
Keeping copies of shared data consistent across cores.
How it works
Cache coherence ensures that all cores see a consistent view of memory when each has its own cache holding copies of the same line. Protocols such as MESI track each line as Modified, Exclusive, Shared or Invalid. Snooping protocols broadcast changes on a bus or interconnect, while directory-based protocols track sharers for larger systems. A write invalidates or updates other copies.
Step-by-step walkthrough
- Both cores read x = 5 into their caches.
- Core 2 reads the same line.
- Core 1 writes x = 6 and invalidates other copies.
- Core 2's next read misses and gets the updated value.
- The MESI protocol tracks lines as Modified, Exclusive, Shared or Invalid.
Where it is used
All multicore and multiprocessor systems implement coherence in hardware, which makes shared-memory programming possible without manual cache flushes. It underlies the behavior of locks and atomic operations.
Common pitfall
Coherence traffic is costly: false sharing, where independent variables sit on the same cache line, makes cores fight over ownership and slows programs dramatically. Coherence does not by itself define ordering between different addresses; that is the memory consistency model. Pad hot variables to separate cache lines.
Where it fits in the course
Cache Coherence is topic 38 of 51 in Computer Architecture & Logic, rated Advanced. It follows Multicore Processors. The next topic is SIMD and Vector Processing.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Computer Architecture & Logic quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Computer Architecture & Logic quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Cache Coherence?
Where do people use Cache Coherence?
What is the most common mistake with Cache Coherence?
What should I learn before this topic?
How can I practice it?
Is Cache Coherence hard to learn?
How long does it take to learn Cache Coherence?
Which topics are related to Cache Coherence?
What should I study after Cache Coherence?
Related topics
- Multicore Processors (Computer Architecture & Logic)
- SIMD and Vector Processing (Computer Architecture & Logic)
- Speculative Execution (Computer Architecture & Logic)
- GPU Architecture (Computer Architecture & Logic)
- LRU Cache Structure (Data Structures)