Something happened when I used this feature that Was hard for me to understand Code:
atomic_size_t example;
example.store(100, memory_order_release);
//Now example.load() is 100;
auto result = example.compare_exchange_weak(1000, 50, memory_order_relaxed) << endl;
//Now result is zero(false) and example.load() is 100,I knew it would.
result = example.compare_exchange_weak(1000, 50, memory_order_relaxed) << endl;
//But now !!! result is One(true)! and example.load() is 50 Why???
What happens after the function is executed? Why are the two executions different? I can't understand why this happened, so I really hope you can answer my question.Thank u very much.
Aucun commentaire:
Enregistrer un commentaire