Note that there are some explanatory texts on larger screens.

plurals
  1. POBest practice for using the 'volatile' keyword in VS2012
    text
    copied!<p>Since upgrading our development and build environments from VS2008 to VS2012, I am confused about the implications of using the <code>volatile</code> keyword in our legacy codebase (it's quite extensive as there is a much copied pattern for managing threads from the "old" days).</p> <p>Microsoft has the following remarks in the VS2012 documentation:</p> <blockquote> <p>If you are familiar with the C# <strong>volatile</strong> keyword, or familiar with the behavior of <strong>volatile</strong> in earlier versions of Visual C++, be aware that the C++11 ISO Standard <strong>volatile</strong> keyword is different and is supported in Visual Studio when the <code>/volatile:iso</code> compiler option is specified. (For ARM, it's specified by default). The <strong>volatile</strong> keyword in C++11 ISO Standard code is to be used only for hardware access; do not use it for inter-thread communication. For inter-thread communication, use mechanisms such as <code>std::atomic&lt;T&gt;</code> from the C++ Standard Template Library.</p> </blockquote> <p>It goes on to say:</p> <blockquote> <p>When the <code>/volatile:ms</code> compiler option is used—by default when architectures other than ARM are targeted—the compiler generates extra code to maintain ordering among references to volatile objects in addition to maintaining ordering to references to other global objects.</p> </blockquote> <p>I take this to mean, that our existing code won't break but won't necessarily be portable (not a problem for us).</p> <p>However, it does raise these questions, on which I would like some advice, if possible:</p> <ol> <li>Should we remove uses of <code>volatile</code> qualifiers in our our code and replace with C++11 ISO Standard compliant equivalents, even though we would not port the code away from MS?</li> <li>If we don't do the above, is there any downside?</li> </ol> <p>I appreciate that this is not really a specific programming problem but we're embarking on some quite major refactoring and I would like to be able to offer some sensible guidelines for this work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload