At 1:27 PM -0800 3/19/03, Boehm, Hans wrote:
>
>3) This can obviously deadlock even with a single thread, so we
>patch this by detecting the most obvious deadlock case which
>involves a recursive invocation of class initialization from the
>same thread. In that case we allow the (partially) uninitialized
>class to be used instead. This causes some strange behavior, but
>since most classes presumably contain many methods that rely on only
>compile-time initialization, it allows some interesting cases to
>work correctly.
Actually, the spec already handles the potential for deadlock in a
single thread.
class A {
static int x;
static {
System.out.println("B.y = " + B.y);
x = 1;
}
}
class B {
static int y;
static {
System.out.println("A.x = " + A.x);
y = 1;
}
}
class Test {
public static void main(String args[]) {
System.out.println("A.x = " + A.x);
}
}
Invoking java Test is guaranteed to print:
A.x = 0
B.y = 1
A.x = 1
So initialization circularities experienced by a single thread
can allow a program to see incompletely initialized classes.
But when experienced by multiple threads, you get deadlock rather
than incompletely initialized classes.
So rather than having to worry about two different bad behaviors,
maybe we should have just one.
Bill
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:42 EDT