False Sharing and Atomic Variables

后端 未结 3 545
栀梦
栀梦 2021-01-12 07:21

When different variables are inside the same cache line, you can experience False Sharing, which means that even if two different threads (running on different cores) are ac

3条回答
  •  逝去的感伤
    2021-01-12 08:07

    A clarification: for negative consequences at least some accesses to "falsely shared" variables should be writes. If writes are rare, performance impact of false sharing is rather negligible; the more writes (and so cache line invalidate messages) the worse performance.

    Even with atomics, cache line sharing (either false or true) still matters. Look for some evidence here: http://www.1024cores.net/home/lock-free-algorithms/first-things-first. Thus, the answer is - yes, placing atomic variables used by different threads to the same cache line may make application slower compared to placing them to two different lines. However, I think it will be mostly unnoticed, unless the app spends a significant portion of its time updating these atomic variables.

提交回复
热议问题