Volatile (computer programming): Difference between revisions

Content deleted Content added
In Java: clarified the global ordering over volatiles
Line 207:
==In Java==
The [[Java programming language]] also has the <code>volatile</code> keyword, but it is used for a somewhat different purpose. When applied to a field, the Java qualifier <code>volatile</code> provides the following guarantees:
*In all versions of Java, there is a global ordering on the reads and writes toof aall volatile variablevariables (this global ordering on volatiles is a partial order over the larger ''synchronization order'' (which is a total order over all ''synchronization actions'')). This implies that every [[thread (computer science)|thread]] accessing a volatile field will read its current value before continuing, instead of (potentially) using a cached value. (However, there is no guarantee about the relative ordering of volatile reads and writes with regular reads and writes, meaning that it's generally not a useful threading construct.)
*In Java 5 or later, volatile reads and writes establish a [[happened-before|happens-before relationship]], much like acquiring and releasing a mutex.<ref>Section 17.4.4: Synchronization Order
{{cite web