|
|
|
|
|
by shultays
293 days ago
|
|
The comments show the values each thread observed.
Why? Nothing in that code implies any synchronization between threads and force an ordering. thread_2 can fetch value of y before 1 writes to it which would set b to 0.You would need additional mechanisms (an extra atomic that you compare_exchange) to force order edit: but I guess the comment means it is the thing author wants to observe Now, the big question: is this execution even possible under the C++ memory model?
sure, use an extra atomic to synchronize threads |
|
In other words, the author considers this execution to be surprising under the C++ memory model, and then goes on to explain it.