In layman’s terms, values marked as volatile may change unpredictably, so they cannot be cached and should be read from main memory each time. Auto-increment operation, this value may change between reading and writing, so the correct result cannot be written. Again, this value changes uncontrollably, so the invariant may not be satisfied.
In layman’s terms, values marked as volatile may change unpredictably, so they cannot be cached and should be read from main memory each time.
Auto-increment operation, this value may change between reading and writing, so the correct result cannot be written.
Again, this value changes uncontrollably, so the invariant may not be satisfied.
It should be that
volatile
the atomicity of the operation cannot be guaranteedSee: The meaning of volatile keyword in java