Strongly Happens Before?
It started innocently enough. I just wanted to brush up on C++ memory orderings. It’s been a while since I last stared into the abyss of std::atomic , so I figured, why not revisit some good ol’ std::memory_order mayhem?
Then I saw it. Strongly happens before.
Wait, what? When did we get a stronger version of happens before?
Turns out, it has been there for quite some time (since C++20 in fact), and it’s actually solving a very real problem in the memory model. If you’re also wondering what it is, why it exists, and whether you should care — that’s exactly what we’re going to explore today.
A simple program to start
Let’s start off with a small program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include
The comments show the values each thread observed. Now, the big question: is this execution even possible under the C++ memory model?
Modification Order
... continue reading