gpt4 book ai didi

c++ - 为什么内存_order_release直到C++20才支持?

转载 作者:行者123 更新时间:2023-12-02 03:10:04 28 4
gpt4 key购买 nike

https://en.cppreference.com/w/cpp/atomic/memory_order

从cppreference来看,memory_order_release可以使用到C++20吗?谁能解释一下为什么 C++ 标准会删除这个以及之后我们应该使用哪一个内存顺序。

最佳答案

这只是对 cppreference 格式的误解。并不是“until C++20”这一行,而是整个 block 。

C++20 中未删除

memory_order_release。只是 memory_order 本身被重新指定为弱枚举:

typedef enum memory_order {
memory_order_relaxed,
memory_order_consume,
memory_order_acquire,
memory_order_release,
memory_order_acq_rel,
memory_order_seq_cst
} memory_order;

到枚举类(由于 P0439 ):

enum class memory_order : /*unspecified*/ {
relaxed, consume, acquire, release, acq_rel, seq_cst
};
inline constexpr memory_order memory_order_relaxed = memory_order::relaxed;
inline constexpr memory_order memory_order_consume = memory_order::consume;
inline constexpr memory_order memory_order_acquire = memory_order::acquire;
inline constexpr memory_order memory_order_release = memory_order::release;
inline constexpr memory_order memory_order_acq_rel = memory_order::acq_rel;
inline constexpr memory_order memory_order_seq_cst = memory_order::seq_cst;

所有六个内存操作仍然存在,并且仍然可以使用相同的拼写进行访问(尽管不鼓励使用 consume)。

关于c++ - 为什么内存_order_release直到C++20才支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61714426/

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