c++ - Best practice for using the 'volatile' keyword in VS2012 -


since upgrading our development , build environments vs2008 vs2012, confused implications of using volatile keyword in our legacy codebase (it's quite extensive there copied pattern managing threads "old" days).

microsoft has following remarks in vs2012 documentation:

if familiar c# volatile keyword, or familiar behavior of volatile in earlier versions of visual c++, aware c++11 iso standard volatile keyword different , supported in visual studio when /volatile:iso compiler option specified. (for arm, it's specified default). volatile keyword in c++11 iso standard code used hardware access; not use inter-thread communication. inter-thread communication, use mechanisms such std::atomic<t> c++ standard template library.

it goes on say:

when /volatile:ms compiler option used—by default when architectures other arm targeted—the compiler generates code maintain ordering among references volatile objects in addition maintaining ordering references other global objects.

i take mean, our existing code won't break won't portable (not problem us).

however, raise these questions, on advice, if possible:

  1. should remove uses of volatile qualifiers in our our code , replace c++11 iso standard compliant equivalents, though not port code away ms?
  2. if don't above, there downside?

i appreciate not specific programming problem we're embarking on quite major refactoring , able offer sensible guidelines work.

  1. if have time it. benefits not great - c++11 atomics may allow more precise control on precisely kind of synchronization need, , have more defined semantics, may allow compiler optimize code better.
  2. in theory, very unlikely, future version of compiler might drop support ms-style volatile completely. or 1 day want port away ms compiler, if stay on windows. if you're doing refactoring, might time work of replacing volatiles atomics, saving doing work in future.

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -