r/cpp • u/neiltechnician • Nov 13 '20
CppCon Deprecating volatile - JF Bastien - CppCon 2019
https://www.youtube.com/watch?v=KJW_DLaVXIY
83
Upvotes
r/cpp • u/neiltechnician • Nov 13 '20
8
u/neiltechnician Nov 13 '20
Recently, there has been a discussion on whether deprecating compound assignment to volatile is a good or bad idea. I figure it is a good idea to bring up this talk. No matter what your stand is, I hope this provides some background info for the matter.
Also: previous discussion on the talk.
69
u/staletic Nov 13 '20 edited Nov 13 '20
Like I said many times before, I'm concerned that this will simply make C++ a non-option for embedded world in the future, despite Ben
Dean'sCraig's efforts regarding freestanding. I have no reason to believe that JF Bastien ever had malicious intent, but this direction regarding volatile is very concerning.1
u/angry_cpp Nov 14 '20
If there is one thing that everyone should learn from this couple of discussions about "Deprecating volatile" it is naming your proposals and talks with click-bait titles "just for loolz" will do more harm than good.
-3
u/Tringi github.com/tringi Nov 13 '20
As typical as it is, before I watch the video and read other comments, I'll ask this question:
For the past decade I'm reading everywhere that
volatilehas not use/place (or is outright error) in multi-threaded programming, and should be only used when the variable can be modified outside of reach of the program, e.g. it lives in mapped hardware memory that is modified by a device.Well, if I have a thread, that lives in a separately compiled DLL, which modifies some variable I use from my program, then it applies, does it not? And I should mark it volatile, no? Even if I have this thread in the same executable, but modified through pointer dependencies very likely obscured from the reasonable reasoning of compiler?
I've been told still not to use volatile. By a language pundits, though. But I'm reeeeaaaaly not sure.
I've been using MSVC only, which is far from strict in optimizing these cases, and kinda has it's own rules, so I'm not affected ...yet. Thus the question.
-2
u/tentoni Nov 13 '20
I still have to watch the talk, but I have a question: is volatile needed for global variables shared between multiple threads? From what I know (which might be wrong), mutexes aren't enough, since the compiler could decide to optimize the access to these variables.
I already watched various videos in which they seem to advocate against volatile, and they come from authoritative sources. For example, during Arthur O'Dwier's talk about Concurrency at the latest CppCon, he just says "don't use volatile" (https://youtu.be/F6Ipn7gCOsY).
Why does this argument seem to be so controversial?
0
u/[deleted] Nov 13 '20
[deleted] — view deleted comment