因为读 Ardanlabs 的 Go Scheduler 这篇文章(
https://www.ardanlabs.com/blog/2018/08/scheduling-in-go-part1.html )时,讲到 cache 时这么写道:
If one Thread on a given core makes a change to its copy of the cache line, then through the magic of hardware, all other copies of the same cache line have to be marked dirty. When a Thread attempts read or write access to a dirty cache line, main memory access (~100 to ~300 clock cycles) is required to get a new copy of the cache line.
修改 cache line 就会导致其他 CPU 的 cache 失效,但我觉得不是 cache 修改写回内存时才会这样吗?不然为什么要使用同步原语同步内存呢?有了困惑。