Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Reading a shared primitive variable in one thread may not yield the value of the most recent write to the variable from another thread. Consequently, the thread may observe a stale value of the shared variable. To ensure the visibility of the most recent update, the write to the variable must happen before the read ([ISO/IEC 9899:2011] subclause 5.1.2.4 paragraph 18). Atomic operations—other than relaxed atomic operations—trivially satisfy the happens before relationship. Where atomic operations are inappropriate, protecting both reads and writes with a mutex also satisfies the happens before relationship.

 

*********** Text below this note not yet converted from Java to C! ************

Noncompliant Code Example (Non-volatile Flag)

...