Course contentsShow
← Computer Science
Lesson 1124 of 2,87226. Memory Hierarchy and CachingFree lesson

Cache Coherence Problem

The challenge of keeping multiple caches consistent when multiple processors share the same memory.

Cache Coherence Problem

What you'll learn: You'll discover why having multiple processors with their own caches creates a consistency challenge in shared-memory systems.

The Challenge of Multiple Caches

Imagine you and a friend are each reading from your own personal copies of a shared notebook. If your friend updates their copy, you won't see the change in yours — suddenly, you're working with outdated information!

This is exactly what happens in multiprocessor systems. When multiple CPUs each have their own cache (like L1 or L2), and they all share the same main memory, a serious problem emerges: cache coherence.

How the Problem Occurs

Consider this scenario:

  1. Processor A reads a value from memory address X into its cache (value = 5)
  2. Processor B also reads the same address X into its cache (value = 5)
  3. Processor A writes a new value (10) to its cache copy of X
  4. If Processor A uses write-back policy, main memory isn't updated yet
  5. Processor B still sees the old value (5) in its cache

Now the system has inconsistent data — different processors see different values for the same memory location. This violates the fundamental expectation that memory should behave consistently.

Why It Matters

Without solving cache coherence, parallel programs would produce unpredictable results. One processor might read stale data while another has already modified it, leading to race conditions and incorrect computations.

The cache coherence problem becomes critical as soon as you have more than one cache potentially holding copies of the same memory location.

Key Takeaway: The cache coherence problem arises when multiple processors maintain private caches of shared memory, requiring special protocols to ensure all caches see a consistent view of data.