For 80x86, if the value is in both CPU's caches then the cache line would be in the "shared" state. If the first CPU wants to modify the cache line, then it has to tell the other CPU/s to invalidate their copy of the cache line first (to get the cache line into the "exclusive" state), and after the first CPU has modified the cache line it would be set to the "modified" state in the first CPU. Now, if the other CPU wants to read that cache line again it'd look in it's cache and find nothing (as the cache line was invalidated) and it'd need to ask for the cache line again. The current copy of the cache line would be sent from the first CPU to the other CPU and the cache line would return to the "shared" state. You would not get a stale value from RAM.LoseThos wrote:Suppose you have two cores and a global memory variable which is cached. They both have accessed recently so each core has it in it's local cache. Core #0 changes it. Core #0 can write-back invalidate cache, writing everything out of cache. (Just pushing one value from cache to mem would be good, but WbInvd does the job.) Now, you have core #1... how do you fetch the updated value sitting in memory when you have a different value in your local cache?
Basically what I'm saying is that the hardware uses MESI cache states to ensure that all caches remain coherent, and an instruction that bypasses the MESI states and gets a value directly from RAM would usually get a wrong/stale value from RAM (instead of getting the right/current value from wherever it currently is).
Cheers,
Brendan