vendredi 5 janvier 2018

std::memory_order_relaxed atomicity with respect to the same atomic variable

The cppreference documentation about memory orders says

Typical use for relaxed memory ordering is incrementing counters, such as the reference counters of std::shared_ptr, since this only requires atomicity, but not ordering or synchronization (note that decrementing the shared_ptr counters requires acquire-release synchronization with the destructor)

Does this mean that relaxed memory ordering don't actually result in atomicity with respect to the same variable? But rather just results in eventual consistency with respect to other relaxed memory loads and/or compare_exchanges? Using std::memory_order_seq_cst would be the only way to see consistent results when paired with std::memory_order_relaxed?

I was under the assumption that std::memory_order_relaxed is still atomic with respect to the same variable but does not provide any other constraints about loads and stores with respect to other data.

Aucun commentaire:

Enregistrer un commentaire