False Sharing and Atomic Variables

后端 未结 3 569
栀梦
栀梦 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 07:53

    If you use atomic variables with the strongest consistency requirements, a full memory barrier, the effect of false sharing will probably not be noticeable. For such an access the performance of an atomic operation is basically limited by the memory access latency. So things are slow anyhow, I don't think they would get much slower in the presence of false sharing.

    If you have other less intrusive memory orderings the performance hit by the atomics itself may be less, and so the impact of false sharing might be significant.

    In total, I would first look at the performance of the atomic operation itself before worrying about false sharing for such operations.

提交回复
热议问题