/** Test if this module is working. */ public static void selfTest() { System.out.print("Enter Condition2.selfTest\n"); Lock lock = new Lock(); Condition2 condition = new Condition2(lock); KThread t[] = new KThread[10]; for (int i = 0; i < 10; i++) { t[i] = new KThread(new Condition2Test(lock, condition)); t[i].setName("Thread" + i).fork(); } KThread.yield(); lock.acquire(); System.out.print("condition.wake();\n"); condition.wake(); System.out.print("condition.wakeAll();\n"); condition.wakeAll(); lock.release(); System.out.print("Leave Condition2.selfTest\n"); t[9].join(); }
public static void selfTest() { comm = new Communicator(); KThread t6 = new KThread(new TestListener()).setName("Listener 1"); t6.fork(); KThread t7 = new KThread(new TestListener()).setName("Listener 2"); t7.fork(); KThread t8 = new KThread(new TestListener()).setName("Listener 3"); t8.fork(); KThread t9 = new KThread(new TestListener()).setName("Listener 4"); t9.fork(); KThread t10 = new KThread(new TestListener()).setName("Listener 5"); t10.fork(); KThread t1 = new KThread(new TestSpeaker(123)).setName("Speaker 1"); t1.fork(); KThread t2 = new KThread(new TestSpeaker(456)).setName("Speaker 2"); t2.fork(); KThread t3 = new KThread(new TestSpeaker(789)).setName("Speaker 3"); t3.fork(); KThread t4 = new KThread(new TestSpeaker(101112)).setName("Speaker 4"); t4.fork(); KThread t5 = new KThread(new TestSpeaker(131415)).setName("Speaker 5"); t5.fork(); t1.join(); t2.join(); t3.join(); t4.join(); t5.join(); t6.join(); t7.join(); t8.join(); t9.join(); t10.join(); KThread.yield(); }
public void run() { for (int i = 0; i < 5; i++) { System.out.println("*** thread " + which + " looped " + i + " times"); currentThread.yield(); } }