Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider $version (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.

...

Noncompliant Code Example

The following non-compliant noncompliant 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.

...

Noncompliant Code Example

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

...