JavaMemoryModel: Finalizer question

From: Bill Pugh (pugh@cs.umd.edu)
Date: Mon Apr 19 2004 - 15:06:30 EDT


OK, here is a quick finalizer question.

class A {
   static A g;
   long x;
   protected void finalize() {
     g = this;
     long r1 = x;
     // ...
     }
   }

   Thread 1:
    A r2 = new A();
    r2.x = 1;
    r2.x = -1;

   Thread 2:
   do {
     r3 = A.g;
     } while (r3 == null);
   r4 = r3.x;

Are we guaranteed that r1 and r4 will both see the value -1?

At a intuitive level, before running the finalizer on an object o,
we need to make sure that if two conflicting writes w1 and w2
have been performed to a field/element of o, and w1 happens-before
w2, then we need to make sure that before the finalizer is run, the
write w1 becomes no longer accessible.

---

Bill

------------------------------- JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:05 EDT