Can false sharing lead to wrong results?

北城以北 提交于 2019-12-11 10:53:34

问题


As I know, false sharing occurs when two cpu cores access different parts of a single memory block. In this case, the L1 caches in each core contains different values.

What is the effect of false sharing? Do commodity CPUs always detect a false sharing? Can it lead to something like a race condition (persisting different cache versions in the memory)?


回答1:


False sharing occurs when one core modifies some data, and another reads some unrelated data that happens to lie in the same cache line. The modification forces the second core to reload the whole cache line, even though the data it's using is unchanged.

This won't cause any incorrect behaviour unless the cache is horribly broken. But it can have a large performance impact, as cached data is unnecessarily fetched from higher level caches.



来源:https://stackoverflow.com/questions/29610284/can-false-sharing-lead-to-wrong-results

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!