by raphlinus · 6y ago · 0 comments
There is definitely precedent for using "volatile" in multithreaded code (though, researching this, I think there may be stronger precedents in C than in C++, see [1], particularly the "In C++11, normally never use volatile for threading, only for MMIO" answer). I agree a good argument can be made that it's incorrect. To be clear, the argument that volatile is incorrect for multithreading is extremely strong from the perspective of standard C and C++, but I think in practice it was considered quite usable.
I have a feeling we agree on the substance (a memory model is a dramatic improvement over using volatile), but I can probably improve the wording.
[1]: https://stackoverflow.com/questions/4557979/when-to-use-vola...
ETA: Here's what I consider a great reference for the widespread use of volatile for multithreaded programming. It's from 2001, but by Andrei Alexandrescu, who I think can be considered an authority: https://www.drdobbs.com/cpp/volatile-the-multithreaded-progr...
https://github.com/raphlinus/raphlinus.github.io/commit/6b92...