1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package art; 18 19 public class OtherThread { 20 public static void doTestOtherThreadWait() throws Exception { 21 System.out.println("################################"); 22 System.out.println("### Other thread (suspended) ###"); 23 System.out.println("################################"); 24 final ControlData data = new ControlData(); 25 data.waitFor = new Object(); 26 Thread t = new Thread("OtherThread doTestOtherThreadWait") { 27 public void run() { 28 Recurse.foo(4, 0, 0, data); 29 } 30 }; 31 t.start(); 32 data.reached.await(); 33 Thread.yield(); 34 Thread.sleep(500); // A little bit of time... 35 36 System.out.println("From top"); 37 PrintThread.print(t, 0, 25); 38 PrintThread.print(t, 1, 25); 39 PrintThread.print(t, 0, 5); 40 PrintThread.print(t, 2, 5); 41 42 System.out.println("From bottom"); 43 PrintThread.print(t, -1, 25); 44 PrintThread.print(t, -5, 5); 45 PrintThread.print(t, -7, 5); 46 47 // Let the thread make progress and die. 48 synchronized(data.waitFor) { 49 data.waitFor.notifyAll(); 50 } 51 t.join(); 52 } 53 54 public static void doTestOtherThreadBusyLoop() throws Exception { 55 System.out.println("###########################"); 56 System.out.println("### Other thread (live) ###"); 57 System.out.println("###########################"); 58 final ControlData data = new ControlData(); 59 Thread t = new Thread("OtherThread doTestOtherThreadBusyLoop") { 60 public void run() { 61 Recurse.foo(4, 0, 0, data); 62 } 63 }; 64 t.start(); 65 data.reached.await(); 66 Thread.yield(); 67 Thread.sleep(500); // A little bit of time... 68 69 System.out.println("From top"); 70 PrintThread.print(t, 0, 25); 71 PrintThread.print(t, 1, 25); 72 PrintThread.print(t, 0, 5); 73 PrintThread.print(t, 2, 5); 74 75 System.out.println("From bottom"); 76 PrintThread.print(t, -1, 25); 77 PrintThread.print(t, -5, 5); 78 PrintThread.print(t, -7, 5); 79 80 // Let the thread stop looping and die. 81 data.stop = true; 82 t.join(); 83 } 84 } 85