blob: 0748433a20d10e401ea48800cd04a15e519283e9 [file] [log] [blame]
Andreas Gampe966de9e2017-01-12 20:51:02 -08001/*
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
17public class OtherThread {
18 public static void doTestOtherThreadWait() throws Exception {
19 System.out.println("################################");
20 System.out.println("### Other thread (suspended) ###");
21 System.out.println("################################");
22 final ControlData data = new ControlData();
23 data.waitFor = new Object();
24 Thread t = new Thread() {
25 public void run() {
26 Recurse.foo(4, 0, 0, data);
27 }
28 };
29 t.start();
30 data.reached.await();
31 Thread.yield();
32 Thread.sleep(500); // A little bit of time...
33
34 System.out.println("From top");
35 PrintThread.print(t, 0, 25);
36 PrintThread.print(t, 1, 25);
37 PrintThread.print(t, 0, 5);
38 PrintThread.print(t, 2, 5);
39
40 System.out.println("From bottom");
41 PrintThread.print(t, -1, 25);
42 PrintThread.print(t, -5, 5);
43 PrintThread.print(t, -7, 5);
44
45 // Let the thread make progress and die.
46 synchronized(data.waitFor) {
47 data.waitFor.notifyAll();
48 }
49 t.join();
50 }
51
52 public static void doTestOtherThreadBusyLoop() throws Exception {
53 System.out.println("###########################");
54 System.out.println("### Other thread (live) ###");
55 System.out.println("###########################");
56 final ControlData data = new ControlData();
57 Thread t = new Thread() {
58 public void run() {
59 Recurse.foo(4, 0, 0, data);
60 }
61 };
62 t.start();
63 data.reached.await();
64 Thread.yield();
65 Thread.sleep(500); // A little bit of time...
66
67 System.out.println("From top");
68 PrintThread.print(t, 0, 25);
69 PrintThread.print(t, 1, 25);
70 PrintThread.print(t, 0, 5);
71 PrintThread.print(t, 2, 5);
72
73 System.out.println("From bottom");
74 PrintThread.print(t, -1, 25);
75 PrintThread.print(t, -5, 5);
76 PrintThread.print(t, -7, 5);
77
78 // Let the thread stop looping and die.
79 data.stop = true;
80 t.join();
81 }
82}