My compiler is clang 18.1.0-rc1; and the following code triggers two warnings:
#include <atomic>
std::atomic<int> n;
int main() {
// Warning: Memory order argument to atomic operation is invalid
n.load(std::memory_order_acq_rel);
// Warning: Memory order argument to atomic operation is invalid
n.store(1, std::memory_order_acq_rel);
}
What's the legal usage of std::memory_order_acq_rel
?
Update
n.fetch_add(1, std::memory_order_acq_rel); // now is ok
It's valid with RMWs like fetch_add
that both load and store in one operation.
The acquire part of acq_rel
is valid for the load side, the release part is valid for the store side.