gpt4 book ai didi

c++ - exchange 或 compare_and_exchange 是否读取修改顺序中的最后一个值?

转载 作者:太空狗 更新时间:2023-10-29 20:27:56 24 4
gpt4 key购买 nike

我正在阅读 C++ Concurrency in Action安东尼·威廉姆斯。在“了解松散排序”部分,它具有:

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.

这是否意味着这样的操作总是以修改顺序读取最后一个值(如果在约束之前没有额外的线程间发生)? IE。是否有一些缓存更新/等(即使是宽松的顺序)?

最佳答案

是的。 C++ 标准说 (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} 操作都是读取-修改-写入操作。

关于c++ - exchange 或 compare_and_exchange 是否读取修改顺序中的最后一个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14795126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com