When is CPU cache flushed back to main memory

cpucpu-cache

If I have a CPU with two cores, each core has it's own L1 cache, is it possible that Core1 and Core2 caches a same part of memory at the same time?
If it is possible, what the value of the main memory will be if both Core1 and Core2 have edited their value in cache?

Best Answer

If I have a CPU with two cores, each core has it's own L1 cache, is it possible that Core1 and Core2 caches a same part of memory at the same time?

Yes. Performance would be terrible if this wasn't the case. Consider two threads running the same code. You want that code in both L1 caches.

If it is possible, what the value of the main memory will be if both Core1 and Core2 has edited their value in cache?

The old value will be in main memory, which won't matter since neither CPU will read it. Before ejecting a modified value from cache, it must be written to memory. Typically some variant of the MESI protocol is used. In the traditional implementation of MESI, if a value is modified in one cache, it cannot be present at all in any other cache at that same level.

Related Question