Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

... writes that initialize the Helper object and the write to the helper field can be done or perceived out of order. As a result, a thread which invokes getHelper() could see a non-null reference to a helper object, but see the default values for fields of the helper object, rather than the values set in the constructor.

Even if the compiler does not reorder those writes, on a multiprocessor the processor or the memory system may reorder those writes, as perceived by a thread running on another processor.

See also CON28-J. Do not publish partially initialized objects.

Compliant Solution (Volatile)

...

THI06-J. Ensure that threads performing blocking operations can be terminated      11. Concurrency (CON)      CON28-J. Do not publish partially initialized objectsImage Added