[concurrency-interest] Reordering and Immutability
oleksandr.otenko at oracle.com
Wed Feb 6 15:42:59 EST 2013
I am thinking of a case where the CPU already has the value at that
address in cache. The value cached has been GCed long since, and now
that memory is reused by a reference to Resource. If accesses to static
members are not volatile, then what stops the thread from observing the
static initialization completed, and the reference that was not nulled
yet, and pointing somewhere dark.
On the other hand, if there is a ordering constraint on static
initializer finishing, the other threads observing this, and those
threads loading the values of static fields, then any static field
initialization is thread safe without extra requirement to mark it
volatile. Since it seems the point of the remark was that any value can
be observed, I assume there is no ordering constraint, go to original
question: what enforces the order of observing the class is initialized
and loading the reference.
On 06/02/2013 19:21, Stanimir Simeonoff wrote:
> Then it may also return a non-null value that is not even a valid
> It will be a valid reference. It may not properly initialized instance
> but still a valid reference.
> and certainly doesn't necessarily reference a valid Resource instance.
> There is no definition of a valid Resource coming from the snippet but
> the Resource c-tor can be invoked multiple times given the lack of
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest