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?
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
sure, use an extra atomic to synchronize threads