[concurrency-interest] Volatile stores in constructors, disallowed to see the default value
dl at cs.oswego.edu
Wed Nov 27 13:41:47 EST 2013
On 11/27/2013 09:06 AM, Vitaly Davidovich wrote:
> But the issue is whether assignment of the new C instance to some other memory
> must occur after the volatile stores.
Sorry for mis-remembering why I had treated this issue as basically settled:
Unless a JVM always pre-zeros memory (which usually not a good option), then
even if not explicitly initialized, volatile fields must be zeroed
in the constructor body, with a release fence before publication.
And so even though there are cases in which the JMM does not
strictly require mechanics preventing publication reordering
in constructors of classes with volatile fields, the only good
implementation choices for JVMs are either to use non-volatile writes
with a trailing release fence, or to perform each volatile write
with full fencing. Either way, there is no reordering with publication.
Unfortunately, programmers cannot rely on a spec to guarantee
it, at least until the JMM is revised.
More information about the Concurrency-interest