Andreas Gampe | 966de9e | 2017-01-12 20:51:02 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | 4665167 | 2017-04-07 09:00:04 -0700 | [diff] [blame] | 17 | package art; |
| 18 | |
Andreas Gampe | 966de9e | 2017-01-12 20:51:02 -0800 | [diff] [blame] | 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(); |
Andreas Gampe | 8a3d0b8 | 2017-02-14 14:28:32 -0800 | [diff] [blame] | 26 | Thread t = new Thread("OtherThread doTestOtherThreadWait") { |
Andreas Gampe | 966de9e | 2017-01-12 20:51:02 -0800 | [diff] [blame] | 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); |
Paul Duffin | 03004e6 | 2018-05-23 11:52:10 +0100 | [diff] [blame^] | 39 | PrintThread.print(t, 0, 7); |
| 40 | PrintThread.print(t, 2, 7); |
Andreas Gampe | 966de9e | 2017-01-12 20:51:02 -0800 | [diff] [blame] | 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(); |
Andreas Gampe | 8a3d0b8 | 2017-02-14 14:28:32 -0800 | [diff] [blame] | 59 | Thread t = new Thread("OtherThread doTestOtherThreadBusyLoop") { |
Andreas Gampe | 966de9e | 2017-01-12 20:51:02 -0800 | [diff] [blame] | 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 | } |