# Cache snoopy protocols **[Snoopy protocols](https://en.wikipedia.org/wiki/Snooping_(cache_coherence))** 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. ```cpp // compile: g++ -o snoop snoop.cpp -pthread // run: ./snoop // description: simulate cache coherence state transitions #include #include #include std::atomic 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; } ```