Starting with the upgrade of our development and build environments from VS2008 to VS2012, I am confused about the consequences of using the volatile keyword in our old code base (this is quite extensive, since there are many copied templates for managing flows from the "old" days).
In the Microsoft VS2012 documentation, Microsoft has the following comments:
If you are familiar with the C # volatile keyword or familiar with the volatile behavior in earlier versions of Visual C ++, keep in mind that the C ++ 11 ISO Standard mutable keyword is different and supported in Visual Studio when the /volatile:iso option is specified /volatile:iso compiler. (For ARM, it is specified by default). volatile keyword in the C ++ 11 ISO standard is used only for access to hardware; do not use it for cross-threading. To exchange data between threads, use the following methods: std::atomic<T> from the standard C ++ template library.
The following is said:
When the /volatile:ms compiler option is used, by default, when architectures other than ARM are targeted, the compiler generates additional code to maintain order among references to mutable objects in addition to maintaining the order of references to other global objects.
I assume that our existing code will not break, but will not necessarily be portable (not a problem for us).
However, this raises these questions on which I would like to get some advice, if possible:
- Should we remove the use of
volatile qualifiers in our code and replace equivalents compatible with the ISO C ++ 11 standard, even if we do not cancel the code from MS? - If we do not do this, is there a flaw?
I appreciate that this is not a very specific programming problem, but we are embarking on a fairly large refactoring, and I would like to offer some reasonable recommendations for this work.
Roger rowland
source share