Using compound operators as well as increments and decrements (and toggling, in the case of ``++boolean++``s) on primitive fields are not atomic operations. That is, they don't happen in a single step. For instance, when a ``++volatile++`` primitive field is incremented or decremented you run the risk of data loss if threads interleave in the steps of the update. Instead, use a guaranteed-atomic class such as ``++AtomicInteger++``, or synchronize the access.
Title was a bit ambiguous I let you modify it if you think it is a bit redundant.
=== on 18 Jun 2015, 18:36:55 Ann Campbell wrote:
Thank you [~nicolas.peru]. That's what I get for writing the title before I fully understand what the description should say. :)
=== on 19 Jun 2015, 15:50:31 Ann Campbell wrote:
\[~nicolas.peru] I just realized that in response to your 'redundant' comment I simply undid the change you had made. But at root, is there a 'safe' way to increment a ``++volatile++`` var?