3 ms·
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 fe
by shultays 1y 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
- masfuerte 1y agoThe comments show the actual values observed in one particular execution. The author asks if this is compatible with the C++ memory model. In other words, the author considers this execution to be surprising under the C++ memory model, and then goes on to explain it.
- cvoss 1y ago> sure, use an extra atomic to synchronize threads What? That would make the situation worse. The execution has a weird unintuitive quirk where the actions of thread 3 seem to precede the actions of thread 1, which seem to precede the actions of thread 2, yet thread 2 observes an action of thread 3. Stronger synchronization would forbid such a thing. The main question of the article is "Is the memory model _weak enough_ to permit the proposed execution?"