From 944e2233358cd2ffaf8224efee438e059ed60c18 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 26 Feb 2011 12:40:54 -0700 Subject: [PATCH] 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. --- test/Trace.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/Trace.java b/test/Trace.java index 79aa3b421d..e07976888b 100644 --- a/test/Trace.java +++ b/test/Trace.java @@ -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(); }