并发写入同一缓存行中的不同位置 [英] Concurrent writes to different locations in the same cache line

查看:196
本文介绍了并发写入同一缓存行中的不同位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个C ++ 11应用程序,其中两个线程使用指向原始类型的简单指针写入不同但附近的内存位置。我可以确定这两个写入最终都会在内存中(可能是在两者达到 boost :: barrier ),或者存在两个CPU内核拥有自己的包含该数据的缓存行的风险,并且第二个核心刷新其对RAM的修改将覆盖和撤消第一次写入所做的修改?

Suppose I have a C++11 application where two threads write to different but nearby memory locations, using simple pointers to primitive types. Can I be sure that both these writes will end up in memory eventually (probably after both have reached a boost::barrier), or is there a risk that both CPU cores hold their own cache line containing that data, and the second core flushing its modification to RAM will overwrite and undo the modification done by the first write?

我希望缓存一致性将照顾我的所有

I hope that cache coherence will take care of this for me in all situations and on all setups compliant with the C++11 memory model, but I'd like to be sure.

推荐答案

是的高速缓存一致性机制将负责这一点。这称为错误共享,应该通过更好地分隔数据以提高性能来避免。

Yes the cache coherency mechanisms will take care of this. This is called False sharing and should be avoided by better separating the data to increase performance.

这篇关于并发写入同一缓存行中的不同位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆