Sadly I'm stuck with C++98, which I'm using in an embedded application.
My question is: I have a multithreaded application, with various global shared variables (evil, I know). I do protect every access to them using mutexes. Do I also need to declare these global variables as volatile, in order to prevent the compiler from optimizing accesses to them?
Searching online it seems that volatile is absolutely useless for multithreading, but a lot of articles are related to C++11, which did introduce a memory model which recognizes threads, but I'm in C++98 land. I also found some resources that indicate that volatile is instead useful in my case, such as this Barr Group's article.
Let me emphasize the fact that I don't want to get rid of the mutexes at all, or try lock free programming. The mutexes are absolutely staying, I just want to understand if the volatile keyword is needed.