Bill Pugh wrote:
> Now, I will argue feature 1: assuming you aren't playing games with
> ThreadLocals or thread identity, using (2) should never be worse than
> using (1). If using (2) could be worse, Executors become unattractive
> and debugging nearly impossible.
> In particular, say that
> a) some other thread has published a reference to an object x while
> x is being constructed
> b) r1 loads a reference to x in a way that doesn't guarantee
> the object is initialized before the reference is loaded
> c) r2 loads a reference to x, but uses synchronization to
> guarantee that the reference is not loaded until x is
> completely initialized.
> Now, I argue that even if r1 and r2 are run in the same thread,
> r2 should see the correctly initialized version of x.
> If you agree with feature 1, then I further argue for feature 2: if
> task r3 loads two difference references to x, the first incorrectly
> synchronized and the second correctly synchronized, then loads
> through the second reference should be valid, even if loads through
> the first reference are not.
Agreed. Though in practice I would expect the acquisition of the valid
reference to "fix" the invalid one.
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:38 EDT