Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does std::memory_order_acq_rel always trigger warnings in C++11?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

n.fetch_add(1, std::memory_order_acq_rel); // now is ok

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading