> This does not work. According to both the existing specification, and
> proposed new specifications, the write to singletons[i] can be moved
> inside the synchronized block.
It can? I am surprised in the sense that I view memory barriers as implicit
code motion barriers and so, unless the compiler/JIT can be 100% certain
that what it is doing is correct it should not move code across
However, Bill is quite right that the spec does not actually say this.
If this were rewritten in C with POSIX Mutexes would that still be the case?
In any case - yes the double-check is broken - end of story. I was simply
illustrating a commonly suggested non-solution.
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:25 EDT