reordering atomic operations in C++
By default operations on atomic variables are done using the memory_order_seq_cst
semantics, which guarantees that no reordering will be done.
Thus the line: value = 1
cannot be reordered below the atomic assignment: value = 1
, so the line std::cout << value;
will always print 1.
By the same rules, the line: std::cout << value;
cannot be reordered
above the line: while (!ready);
.