I am reading about C++ memory model how these are applied. I really confused when the sequentially consistent model is necessary instead of the acquire-release model. For example let's examine the Dekker's algorithm Reading the following tutorial https://www.think-cell.com/en/career/talks/pdf/think-cell_talk_memorymodel.pdf , it is recommended to use sequentially consistent model for the Dekker's algorithm.
Have a look in the following example
atomic<bool> f1=false;
atomic<bool> f2=false;
//thread 1
f1.store(true, memory_order_seq_cst);
if (!f2.load(memory_order_seq_cst)) {
// critical section
}
f1.store(false);
//thread 2
f2.store(true, memory_order_seq_cst);
if (!f1.load(memory_order_seq_cst)) {
// critical section
}
f2.store(false);
Why the release-acquire model in this case cannot quarantee that store and load operations take place without any reordering?
Thank you George
Aucun commentaire:
Enregistrer un commentaire