12
From book "Java Concurrency in Practice" page 26:
You can use volatile variables only when all the following criteria are met:
Writes to the variable do not depend on its current value, or you can ensure that only a single thread ever updates the value;
The variabledoes not participate in invariants with other state variables; and
- Locking is not required for any other reason while the variable is being accessed.
How to comprehend "The variable does not participate in invariants with other state variables when using volatile keyword"?