educative.io

Why does y=11 and x=0 happen?


According to the lesson, y=11 and x=0 is not a possible result.
but when I tried it on cppmen, I got it.
Is there anything wrong with it?


Course: Modern C++ Concurrency: Get the most out of any machine - Learn Interactively
Lesson: CppMem: Atomics with Sequential Consistency - Modern C++ Concurrency: Get the most out of any machine

Hi @Luis_Tung ,
Thanks for reaching out to us. In this lesson, it is mentioned that All four combinations of y and x are possible: (0,0), (11,0), (0,2000), (11,2000). So, y=11 and x=0 is a possible result and this is the second execution we have shown in the lesson which is not consistent execution.
I hope it helps. Happy Learning :slight_smile:


I don’t think so.
Here is a screenshot from this lesson saying y=11 and x=0 is not possible.

y.store(11) is std::memory_order_seq_cst, so x.store(2000) always happens before y.store(11) from thread2’s point of view.