use wait/notifyAll too avoid starvation in Trace test

Thread.yield is not enough to ensure that the tracing thread does not
starve the test thread on some QEMU VMs, so we use wait/notifyAll to
make sure both threads have opportunities to run and the test actually
finishes.
This commit is contained in:
Joel Dice 2011-02-26 12:40:54 -07:00
parent a4c4d54cdd
commit 944e223335

View File

@ -67,10 +67,16 @@ public class Trace implements Runnable {
if (i % 100 == 0) {
System.out.print("r");
System.out.flush();
synchronized (this) {
notifyAll();
}
}
}
} finally {
alive = false;
synchronized (this) {
alive = false;
notifyAll();
}
}
}
@ -88,7 +94,7 @@ public class Trace implements Runnable {
++ count;
if (count % 100 == 0) {
Thread.yield();
trace.wait();
System.out.print("t");
System.out.flush();
}