summaryrefslogtreecommitdiff
path: root/test/051-thread/src/Main.java
diff options
context:
space:
mode:
author Brian Carlstrom <bdc@google.com> 2014-08-27 23:43:46 -0700
committer Brian Carlstrom <bdc@google.com> 2014-08-28 15:37:27 -0700
commitba32de47e32f436d7c11cb4a2e78bdd4ad4dc5d2 (patch)
tree1b56397dfce317d2034feebfb2191bcb09b78823 /test/051-thread/src/Main.java
parent14515d738dadf88e3e00b7dd1bd69899c4df4b91 (diff)
Fix issue with Thread.setName hanging after Thread.start
When suspending a thread by peer the invariant that only attached threads are suspended must be maintained. Add a ThreadList::Contains check which requires making this method non-static. Add some extra thread logging. Bug: 17302037 (cherry picked from commit 37c16453a92bbf1a47f042000318a1b60381017d) Change-Id: I51832785d4b4b431e035318e75635f442e89a1fb
Diffstat (limited to 'test/051-thread/src/Main.java')
-rw-r--r--test/051-thread/src/Main.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/051-thread/src/Main.java b/test/051-thread/src/Main.java
index 608b7e0878..390685d049 100644
--- a/test/051-thread/src/Main.java
+++ b/test/051-thread/src/Main.java
@@ -25,6 +25,7 @@ public class Main {
testThreadCapacity();
testThreadDaemons();
testSleepZero();
+ testSetName();
System.out.println("thread test done");
}
@@ -112,4 +113,24 @@ public class Main {
}
System.out.print("testSleepZero finished\n");
}
+
+ private static void testSetName() throws Exception {
+ System.out.print("testSetName starting\n");
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ System.out.print("testSetName running\n");
+ }
+ };
+ thread.start();
+ thread.setName("HelloWorld"); // b/17302037 hang if setName called after start
+ if (!thread.getName().equals("HelloWorld")) {
+ throw new AssertionError("Unexpected thread name: " + thread.getName());
+ }
+ thread.join();
+ if (!thread.getName().equals("HelloWorld")) {
+ throw new AssertionError("Unexpected thread name after join: " + thread.getName());
+ }
+ System.out.print("testSetName finished\n");
+ }
}