6988618: JCK test setDaemon0101 hangs on specific machine
authorchegar
Fri, 05 Nov 2010 09:07:02 +0000
changeset 7166 342b279c29a6
parent 7165 cf3291ed2016
child 7167 f5a0fca591f8
6988618: JCK test setDaemon0101 hangs on specific machine Reviewed-by: dholmes, alanb
jdk/src/share/classes/java/lang/Thread.java
jdk/src/share/classes/java/lang/ThreadGroup.java
--- a/jdk/src/share/classes/java/lang/Thread.java	Thu Nov 04 14:42:30 2010 -0700
+++ b/jdk/src/share/classes/java/lang/Thread.java	Fri Nov 05 09:07:02 2010 +0000
@@ -229,7 +229,7 @@
      * after setting this thread's interrupt status.
      */
     private volatile Interruptible blocker;
-    private Object blockerLock = new Object();
+    private final Object blockerLock = new Object();
 
     /* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
      */
@@ -688,16 +688,19 @@
             throw new IllegalThreadStateException();
 
         /* Notify the group that this thread is about to be started
-         * so that it can be added to the group's list of threads. */
+         * so that it can be added to the group's list of threads
+         * and the group's unstarted count can be decremented. */
         group.threadStarting(this);
 
-        boolean failed = true;
+        boolean started = false;
         try {
             start0();
-            failed = false;
+            started = true;
         } finally {
             try {
-                group.threadStarted(this, failed);
+                if (!started) {
+                    group.threadStartFailed(this);
+                }
             } catch (Throwable ignore) {
                 /* do nothing. If start0 threw a Throwable then
                   it will be passed up the call stack */
--- a/jdk/src/share/classes/java/lang/ThreadGroup.java	Thu Nov 04 14:42:30 2010 -0700
+++ b/jdk/src/share/classes/java/lang/ThreadGroup.java	Fri Nov 05 09:07:02 2010 +0000
@@ -870,9 +870,16 @@
     /**
      * Notifies the group that the thread {@code t} is about to be
      * started and adds the thread to this thread group.
+     *
+     * The thread is now a fully fledged member of the group, even though
+     * it hasn't been started yet. It will prevent the group from being
+     * destroyed so the unstarted Threads count is decremented.
      */
     void threadStarting(Thread t) {
-        add(t);
+        synchronized (this) {
+            add(t);
+            nUnstartedThreads--;
+        }
     }
 
     /**
@@ -907,12 +914,10 @@
     }
 
     /**
-     * Notifies the group that the thread {@code t} has completed
+     * Notifies the group that the thread {@code t} has failed
      * an attempt to start.
      *
-     * <p> If the thread has been started successfully
-     * then the group has its unstarted Threads count decremented.
-     * Otherwise the state of this thread group is rolled back as if the
+     * <p> The state of this thread group is rolled back as if the
      * attempt to start the thread has never occurred. The thread is again
      * considered an unstarted member of the thread group, and a subsequent
      * attempt to start the thread is permitted.
@@ -923,16 +928,10 @@
      * @param  failed
      *         true if the thread could not be started successfully
      */
-    void threadStarted(Thread t, boolean failed) {
+    void threadStartFailed(Thread t) {
         synchronized(this) {
-            if (failed) {
-                remove(t);
-            } else {
-                if (destroyed) {
-                    return;
-                }
-                nUnstartedThreads--;
-            }
+            remove(t);
+            nUnstartedThreads++;
         }
     }