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 { doTestOtherThreadWait()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, 7); 40 PrintThread.print(t, 2, 7); 41 PrintThread.print(t, 2, 1); 42 43 System.out.println("From bottom"); 44 PrintThread.print(t, -1, 25); 45 PrintThread.print(t, -5, 5); 46 PrintThread.print(t, -7, 5); 47 48 // Let the thread make progress and die. 49 synchronized(data.waitFor) { 50 data.waitFor.notifyAll(); 51 } 52 t.join(); 53 } 54 doTestOtherThreadBusyLoop()55 public static void doTestOtherThreadBusyLoop() throws Exception { 56 System.out.println("###########################"); 57 System.out.println("### Other thread (live) ###"); 58 System.out.println("###########################"); 59 final ControlData data = new ControlData(); 60 Thread t = new Thread("OtherThread doTestOtherThreadBusyLoop") { 61 public void run() { 62 Recurse.foo(4, 0, 0, data); 63 } 64 }; 65 t.start(); 66 data.reached.await(); 67 Thread.yield(); 68 Thread.sleep(500); // A little bit of time... 69 70 System.out.println("From top"); 71 PrintThread.print(t, 0, 25); 72 PrintThread.print(t, 1, 25); 73 PrintThread.print(t, 0, 5); 74 PrintThread.print(t, 2, 5); 75 76 System.out.println("From bottom"); 77 PrintThread.print(t, -1, 25); 78 PrintThread.print(t, -5, 5); 79 PrintThread.print(t, -7, 5); 80 81 // Let the thread stop looping and die. 82 data.stop = true; 83 t.join(); 84 } 85 } 86