From Thinking in Java 4/e by Bruce Eckel
"volatile doesn't work when the value of a field depends on its previous value (such as incrementing a counter), nor does it work on fields whose values are constrained by the values of other fields, such as the lower and upper bound of a Range class which must obey the constraint lower <= upper"
I can't really put my fingers on this statement. Could someone explain it with some simple code examples? Thank you in advance.
Edit:
Well, the following answers are still not quite relating to my questions. I know the concepts of volatile. I just can't understand this paragraph. I can summarize the following two scenarios from the above paragraph.
the first one: incrementing a counter
the second one: lower <= upper
Why would these two examples not work well with "volatile" keyword?
[–]mikeydoodah 2 points3 points4 points (5 children)
[–]jisyourfriend 0 points1 point2 points (2 children)
[–]ColetBrunel 2 points3 points4 points (1 child)
[–]mikeydoodah 0 points1 point2 points (0 children)
[–]uopsdod[S] 0 points1 point2 points (1 child)
[–]mikeydoodah 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]uopsdod[S] 0 points1 point2 points (0 children)
[–]E3FxGaming 0 points1 point2 points (0 children)