mercredi 8 novembre 2023

C++ "atomic_compare_exchange_strong" apply to non-atomic variable

std::shared_ptr<int> node;
int *expect = new int(1);
int *desire = new int(2);
atomic_compare_exchange_strong(&node, &expect, desire)

What makes this code run as I image? the "node" is not modified by atomic What conditions does "node" need to meet? I think volatile modification is needed in C, but I don’t know what is needed in C++.

I want to ask the apply conditions of atomic_compare_exchange_strong

Aucun commentaire:

Enregistrer un commentaire