38,763
edits
(Updating to match new version of source page) |
(Updating to match new version of source page) |
||
Line 31: | Line 31: | ||
=Pitfalls= | =Pitfalls= | ||
==The <tt>volatile</tt> keyword== | ==The <tt>volatile</tt> keyword== | ||
The reader should note that <tt>volatile</tt> in C and C++ have very specific meanings, e.g., see [http://en.cppreference.com/w/cpp/language/cv this page]. Needing to use <tt>volatile</tt> in C/C++ code is a rare event. Within high-performance computing code, <tt>volatile</tt> in rare instances might be used to declare a variable in order tell the compiler to not optimize away load/store side-effects from/to that variable. That said, '''never''' use volatile for synchronization: use C11/C++11 atomics, locks, etc. instead. Finally, know <tt>volatile</tt> in other programming languages, e.g., Java, is different than | The reader should note that <tt>volatile</tt> in C and C++ have very specific meanings, e.g., see [http://en.cppreference.com/w/cpp/language/cv this page]. Needing to use <tt>volatile</tt> in C/C++ code is a rare event. Within high-performance computing code, <tt>volatile</tt> in rare instances might be used to declare a variable in order tell the compiler to not optimize away load/store side-effects from/to that variable. That said, '''never''' use volatile for synchronization: use C11/C++11 atomics, locks, etc. instead. Finally, know <tt>volatile</tt> in other programming languages, e.g., Java, is often different than in C/C++. Typically the latter would be implemented in C/C++ using synchronization constructs. | ||
==Compilers== | ==Compilers== |