From 8d9044bb4039bfd46b20edce4cff929906e492c6 Mon Sep 17 00:00:00 2001 From: Alex Light Date: Tue, 22 Jul 2014 14:04:31 -0700 Subject: Made sync-test actually wait for first thread to start. This makes sure that the threads execute in the order we expect. Change-Id: I0c4976e72ef2eb9e5fd66184eb1cd4821ea1e42b --- test/050-sync-test/src/Main.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/050-sync-test/src/Main.java b/test/050-sync-test/src/Main.java index ec6d732..5364e2a 100644 --- a/test/050-sync-test/src/Main.java +++ b/test/050-sync-test/src/Main.java @@ -50,13 +50,14 @@ public class Main { one = new CpuThread(1); two = new CpuThread(2); - one.start(); - - try { - Thread.sleep(100); - } catch (InterruptedException ie) { - System.out.println("INTERRUPT!"); - ie.printStackTrace(); + synchronized (one) { + one.start(); + try { + one.wait(); + } catch (InterruptedException ie) { + System.out.println("INTERRUPT!"); + ie.printStackTrace(); + } } two.start(); @@ -101,6 +102,9 @@ class CpuThread extends Thread { //System.out.println(Thread.currentThread().getName()); synchronized (mSyncable) { + synchronized (this) { + this.notify(); + } for (int i = 0; i < 10; i++) { output(mNumber); } -- cgit v1.1