0

I have see this :

Pattern #2: one-time safe publication
The visibility failures that
are possible in the absence of synchronization can get even trickier
to reason about when writing to object references instead of primitive
values. In the absence of synchronization, it is possible to see an
up-to-date value for an object reference that was written by another
thread and still see stale values for that object's state. (This
hazard is the root of the problem with the infamous
double-checked-locking idiom, where an object reference is read
without synchronization, and the risk is that you could see an
up-to-date reference but still observe a partially constructed object
through that reference.)*

from IBMdeveloperworks_volatile

I am confused :

  1. what is 'primitive values'
  2. Why it cause : 'to see an up-to-date value for an object reference that was written by another thread and still see stale values for that object's state'
Timi
  • 892
  • 1
  • 8
  • 17
  • I once asked a question similar to 2 and received an excellent answer: http://stackoverflow.com/questions/24789287/constructors-and-instruction-reordering – Kevin Krumwiede Mar 15 '16 at 04:24

1 Answers1

2

1) primitive values are not object like int,boolean,float etc. Just remember that there are objects equivalents of these such as Integer,Boolean etc.

2) This a thread may see updated object reference but that object may not be initialized completely. e.g this could happen if constructor is not yet completed when this thread get the new updated references of the object... this may be complex but may happen with some JVM implementations.

Nagesh Paraddi
  • 174
  • 1
  • 5