Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider v2.1 (sch jbop) (X_X)@==(Q_Q)@

...

Please keep in mind that while adding volatile will ensure that a compiler does not perform unintended reordering or optimization, it in no way guarantees synchronization between multiple threads or otherwise ward against simultaneous memory accesses.

Non-Compliant

...

Code Example

The following non-compliant code relies on the reception of a SIGINT signal to toggle a flag to terminate a loop.

...

However, if the value of i is cached, the while loop may never terminate. When compiled on GCC with the -O optimization flag, the program fails to terminate even upon receiving a SIGINT.

Non-Compliant

...

Code Example

The following non-compliant code prevents the compiler from optimizing away the loop condition, by typecasting type casting the variable to volatile within the while loop.

...

Wiki Markup
\[[ISO/IEC 9899-:1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.7.3, "Type qualifiers," and Section 7.14, "Signal handling <signal.h>"
\[[ISO/IEC 03|AA. C References#ISO/IEC 03]\] Section 6.7.3, "Type qualifiers"
\[[Sun 05|AA. C References#Sun 05]\] [Chapter 6, "Transitioning to ISO C"|http://docs.sun.com/source/819-3688/tguide.html#pgfId-997898]

...