gpt4 book ai didi

c++ - 为什么 fetch_sub 不是释放操作?

转载 作者:太空狗 更新时间:2023-10-29 21:33:41 27 4
gpt4 key购买 nike

引自 C++ 并发实战 $ list 5.9

A fetch_sub operation with memory_order_acquire semantics doesn’t synchronize-with anything, even though it stores a value, because it isn’t a release operation. Likewise, a store can’t synchronize-with a fetch_or with memory_order_release semantics, because the read part of the fetch_or isn’t an acquire operation.

我很难理解上面的段落。如果 fetch_submemory_order_acquire语义的操作不同步任何东西,为什么fetch_sub接口(interface)给我们留下一个内存顺序参数如下?

T fetch_sub( T arg, std::memory_order order = std::memory_order_seq_cst ) noexcept;

最佳答案

  1. “同步于”是单向的,不可交换的。 “A synchronizes with B”并不意味着“B synchronizes with A”(事实上,恰恰相反),这与人们对英语的期望不同。因此,memory_order_acquire RMW 操作无法与任何内容同步,但是 memory_order_release 存储与 memory_order_acquire RMW 操作同步,后者获取从中读取的值商店。同样,虽然 memory_order_release 存储不与 memory_order_release RMW 同步,但 memory_order_release RMW 可以与 memory_order_acquire 加载。
  2. memory_order_acq_rel

关于c++ - 为什么 fetch_sub 不是释放操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50500443/

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