Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: let's rely on the java lang spec for volatile

...

Anchor
volatile
volatile

volatile : (http://mindprod.com/jgloss/volatile.htmlImage Removed)
The volatile keyword is used on variables that may be modified simultaneously by other threads. This warns the compiler to fetch them fresh each time, rather than caching them in registers. This also inhibits certain optimisations that assume no other thread will change the values unexpectedly. Since other threads cannot see local variables, there is never any need to mark local variables volatile. You need synchronized to co-ordinate changes to variables from different threads, but often volatile will do just to look at them. volatile does not guarantee you atomic access, e.g. a ++;This is similar to, but distinct from the volatile keyword as used in C and C++Declaring a variable volatile ensures that all threads see a consistent value of the variable. Volatile guarantees atomic reads and writes of values, however, it does not guarantee the atomicity of composite operations such as variable incrementation (read-modify-write sequence).