为什么 memory_order_release 支持到 C++20?
Why memory_order_release support until C++20?
https://en.cppreference.com/w/cpp/atomic/memory_order
从 cppreference,memory_order_release 可以使用到 C++20?任何人都可以解释为什么 C++ 标准会删除这个以及之后我们应该使用哪个 memory_order。
这只是对cppreference格式的误解。 "until C++20" 不是那一行,而是整块。
memory_order_release
未在 C++20 中删除。只是 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;
到枚举 class(作为 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
)。
您误读了 table。这是说整个 块 适用于 11 <= C++ < 20.
下面以不同方式定义所有相同常量的块适用于 C++ >= 20.
(C++20 前) 与 memory_order_release
在同一行只是偶然的格式化。请注意 (C++11 起) 与 acquire
在同一行,但显然适用于所有常量,因为 std::atomic 在 C++11 中是新的.
变化是现在有一个 enum class
常量的短名称:
enum class memory_order : /*unspecified*/ {
relaxed, consume, acquire, release, acq_rel, seq_cst
};
并且完整的全局范围名称是根据它定义的,例如作为
inline constexpr memory_order memory_order_release = memory_order::release;
https://en.cppreference.com/w/cpp/atomic/memory_order
从 cppreference,memory_order_release 可以使用到 C++20?任何人都可以解释为什么 C++ 标准会删除这个以及之后我们应该使用哪个 memory_order。
这只是对cppreference格式的误解。 "until C++20" 不是那一行,而是整块。
memory_order_release
未在 C++20 中删除。只是 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;
到枚举 class(作为 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
)。
您误读了 table。这是说整个 块 适用于 11 <= C++ < 20.
下面以不同方式定义所有相同常量的块适用于 C++ >= 20.
(C++20 前) 与 memory_order_release
在同一行只是偶然的格式化。请注意 (C++11 起) 与 acquire
在同一行,但显然适用于所有常量,因为 std::atomic 在 C++11 中是新的.
变化是现在有一个 enum class
常量的短名称:
enum class memory_order : /*unspecified*/ {
relaxed, consume, acquire, release, acq_rel, seq_cst
};
并且完整的全局范围名称是根据它定义的,例如作为
inline constexpr memory_order memory_order_release = memory_order::release;