-
Bug
-
Resolution: Won't Fix
-
P3
-
None
-
1.1
-
sparc
-
solaris_2.5
Name: akC45999 Date: 11/27/96
Specification of java.lang.Thread.join(long millis) says:
Waits at most millis milliseconds for this thread to die.
Meanwhile, in the following test shows that it waits much longer.
Two threads aquire their own monitors and then thats of each other,
so deadlock occurs. The third thread calls join(1) but waits
forever.
-------------------------- t_0.java ------------------------------
interface t_0 {
public void aquire_self ();
public void aquire_peer ();
}
-------------------------- invokeinterface02301.java ------------------------------
public class invokeinterface02301 extends Thread implements t_0 {
t_0 t;
static java.io.PrintStream out;
public static void trace (String msg) {
out.println(Thread.currentThread().getName()+": "+msg);
}
public void run () {
trace("attempt to aquire_self");
aquire_self();
}
public synchronized void aquire_self () {
trace("self aquired");
try {
sleep(100);
} catch (InterruptedException e) {
out.println("InterruptedException:");
}
trace("attempt to aquire_peer:"+t);
t.aquire_peer();
}
public synchronized void aquire_peer () {
trace("peer aquired");
}
public static int run (String argv[], java.io.PrintStream out_p)
{
out=out_p;
invokeinterface02301
th1=new invokeinterface02301()
,th2=new invokeinterface02301()
;
th1.t=th2;
th1.setName("thr 1");
th2.t=th1;
th2.setName("thr 2");
th1.start();
th2.start();
try {
th1.join(1);
} catch (InterruptedException e) {
out.println("InterruptedException:");
}
trace("game over");
int res=2;
if (th1.isAlive()) {
trace("th1 isAlive");
th1.stop();
trace("th1 stopped");
res--;
}
if (th2.isAlive()) {
trace("th2 isAlive");
th2.stop();
trace("th2 stopped");
res--;
}
if (res==1) {
out.println("something wrong");
res=2;
}
return res;
}
public static void main(String argv[])
{
System.exit(run(argv,System.out));
}
}
----------------------- output ----------------------------------
thr 1: attempt to aquire_self
thr 1: self aquired
thr 2: attempt to aquire_self
thr 2: self aquired
thr 1: attempt to aquire_peer:Thread[thr 2,5,main]
thr 2: attempt to aquire_peer:Thread[thr 1,5,main]
main: game over
main: th1 isAlive
-----------------------------------------------------------------
======================================================================