Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: clarified what constitutes a composite operation

Wiki Markup
Composite operations on shared variables (consisting of more than one discrete operation) must be performed atomically. Errors can arise from composite operations that need to be perceived atomically but are not \[[JLS 05|AA. Java References#JLS 05]\]. For example, any assignment that depends on an existing value is a composite operation, for example, {{a = b}}.  Increment {{+\+}} and decrement {{++-\-}} operators depend modify the value of the operand based on the existing value of the operand and are consequently always composite operations. Compound assignments expressions that include a compound assignment operators {{*=, /=, %=, +=, -=, <<=, >>=, >>>=, ^=, or |=}} are always composite operations.  A compound assignment expression of the form __E1 op= E2__ is equivalent to __E1 = (T )((E1) op (E2))__, where __T__ is the type of __E1__, except that __E1__ is evaluated only once.

For example, the following code:

Code Block

short x = 3;
x += 4.6;

results in x having the value 7 because it is equivalent to:

Code Block

short x = 3;
x = (short)(x + 4.6);

For atomicity of a grouping of calls to independently atomic methods of the existing Java API, see CON07-J. Do not assume that a grouping of calls to independently atomic methods is atomic.

...