I'm still trying to understand the rules for final fields.
This vaguely follows the notation of figure 8 in Manson and Pugh's June 6 draft.
Assume T has a field x, and o and p are of class C with final field f.
Initially q is null.
Assume thread 1 does
o.f = new T();
q = o;
If I understand correctly, thread 2 is guaranteed to either see q == null, or to see q.f.x as written by the T constructor?
Now assume I have a static array A of Ts, and a static index variable next_t. Assume final field f now holds an integer index instead of a reference. Effectively I'm just replacing a reference by an integer array index.
Assume thread 1b does:
o.f = next_t++; // reserve slot.
A[o.f] = new T();
q = o;
Now if thread 2b sees a non-null q, there is no guarantee that the initialization by T() of A[q.f].x is visible, since A[q.f].x is not reached by following pointers from q.f?
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:48 EDT