https://en.cppreference.com/w/cpp/atomic/memory_order
From cppreference, memory_order_release can use until C++20? Can anyone explain why C++ Standard will delete this and which one memory_order we should use after that.
This is just a misunderstanding with the formatting of cppreference. It's not that one line that is "until C++20", it's the whole block.
memory_order_release
isn't removed in C++20. It's just that memory_order
itself was respecified from being a weak enum:
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;
to an enum class (as a result of 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;
All six memory operations are still there, and are still accessible with the same spelling (although consume
is discouraged).
You're misreading the table. It's saying that whole block applies to 11 <= C++ < 20.
The block below that defines all the same constants a different way applies to C++ >= 20.
It's just by chance of formatting that the (until C++20) is on the same line as memory_order_release
. Note that (since C++11) is on the same line as acquire
but clearly applies to all the constants because std::atomic was new in C++11.
The change is that there's now an enum class
with short names for the constants:
enum class memory_order : /*unspecified*/ {
relaxed, consume, acquire, release, acq_rel, seq_cst
};
And the full global-scope names are defined in terms of that, e.g. as
inline constexpr memory_order memory_order_release = memory_order::release;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With