交换或compare_and_exchange是否在修改顺序中读取最后一个值? [英] Does exchange or compare_and_exchange reads last value in modification order?

查看:342
本文介绍了交换或compare_and_exchange是否在修改顺序中读取最后一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Anthony Williams的 C ++并发操作
在了解轻松订购部分有:

I am reading C++ Concurrency in Action by Anthony Williams. At section "Understanding Relaxed Ordering" it has:


还有一些额外的东西,你可以告诉男人在隔间,例如记下这个数字,告诉我在列表底部(如果底部有数字,则记下
这个数字)的列表
是;否则告诉我什么I
应该猜到(compare_exchange_strong),但这不影响一般的
原则。

There are a few additional things you can tell the man in the cubicle, such as "write down this number, and tell me what was at the bottom of the list" (exchange) and "write down this number if the number on the bottom of the list is that; otherwise tell me what I should have guessed" (compare_exchange_strong), but that doesn’t affect the general principle.


$ b b

这意味着这样的操作总是在修改顺序中读取最后一个值(如果在约束之前没有额外的线程发生)?也就是说是否有一些缓存更新/ etc(即使在轻松的排序)?

Does it mean that such operations always read last value in modification order (if there are no additional inter-thread happens before constraints)? I.e. are there some caches updates/etc (even in relaxed ordering)?

推荐答案

C ++标准说(29.3 / 10):

Yes. The C++ Standard says (29.3/10):


原子读 - 修改 - 写操作总是读取最后一个值

Atomic read-modify-write operations shall always read the last value (in the modification order) written before the write associated with the read-modify-write operation.

两者 exchange 和成功的 compare_exchange_ {weak,strong} 操作是读 - 修改 - 写操作。

Both exchange and successful compare_exchange_{weak,strong} operations are read-modify-write operations.

这篇关于交换或compare_and_exchange是否在修改顺序中读取最后一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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