Wiki Markup |
---|
Compound operations are operations that consist of more than one discrete operation. Expressions that include postfix and prefix increment ({{\+\+}}), postfix or prefix decrement ({{\-\-}}), or compound assignment operators always result in compound operations. Compound assignment expressions use operators such as {{*=, /=, %=, +=, -=, <<=, >>=, >>>=, ^=}} and {{|=}} \[[JLS 05|AA. Java References#JLS 05]\]. Compound operations on shared variables must be performed atomically to prevent [data races|BB. Definitions#data race] and [race conditions|BB. Definitions#race conditions]. |
For information about the atomicity of a grouping of calls to independently atomic methods belonging that belong to thread-safe classes, see CON07-J. Do not assume that a grouping of calls to independently atomic methods is atomic.
...
This code is also not thread - safe. A data race exists because ^=
is a non-atomic compound operation.
...