Site Tools


cache-snoopy-protocols

Table of Contents

Cache snoopy protocols

Snoopy protocols implement cache coherence over a shared bus: every cache controller watches (“snoops”) all bus transactions regardless of origin and reacts if the address concerns a line it holds. Coherence emerges from every cache independently applying the same rules to the same broadcast traffic, with no central coordinator.

Snoopy protocols scale poorly beyond a few dozen cores because every write broadcasts to all caches, creating bus contention. Directory-based protocols are used for larger systems.

Example

Snoopy coherence state transitions when multiple cores access a shared line.

// compile: g++ -o snoop snoop.cpp -pthread
// run: ./snoop
// description: simulate cache coherence state transitions
 
#include <iostream>
#include <thread>
#include <atomic>
 
std::atomic<int> shared = 0;  // simulates shared cache line
 
int main() {
    std::thread t1([](){ shared = 1; });  // write (broadcast invalidate)
    std::thread t2([](){ int x = shared.load(); });  // read (misses after invalidate)
 
    t1.join();
    t2.join();
 
    std::cout << "Snooped write invalidates other caches\n";
    return 0;
}
cache-snoopy-protocols.md · Last modified: by 127.0.0.1