Turns out, we do have them. libstdc++ contains a heuristic
kludge where it checks if libpthread is linked into the process and conditionally executes an atomic add or non-atomic add depending on the result. Post 2020, it doesn’t directly use the libpthread hack, but uses glibc’s native support for this.
These kinds of things always make me sad about C++ (especially compared to how nice and clean things seem to be in Rust world), but at least it’s nice knowing that the committee did consider it and there are good reasons why to not have this in the C++ stdlib. The most compelling reason is that in the absence of a borrow checker, it is all too easy to silently use a non-atomic shared_ptr in multithreaded code.
Wrote a thread about it:
I get asked why I’m into C++ and not Rust.
Above all, it’s pragmatic. C++ is simply what’s used for the work I aspire to do, and I don’t have time for both.
Beyond that, I still think there’s at least one reason to learn C++ today: out of respect for where it’s gotten us. A lot of lessons to learn from something that powers the world, flaws and all.
And when you do learn Rust, you’ll understand it better. The C++ context will give you a deeper & more intuitive appreciation for why it’s like it is.
Rust wouldn’t be what it is without C++. 🤝