ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166y/ForkJoinWorkerThread.java
(Generate patch)

Comparing jsr166/src/jsr166y/ForkJoinWorkerThread.java (file contents):
Revision 1.49 by dl, Mon Sep 13 09:53:19 2010 UTC vs.
Revision 1.52 by dl, Sun Oct 10 11:56:11 2010 UTC

# Line 751 | Line 751 | public class ForkJoinWorkerThread extend
751  
752      // status check methods used mainly by ForkJoinPool
753      final boolean isRunning()     { return runState == 0; }
754    final boolean isTerminating() { return (runState & TERMINATING) != 0; }
754      final boolean isTerminated()  { return (runState & TERMINATED) != 0; }
755      final boolean isSuspended()   { return (runState & SUSPENDED) != 0; }
756      final boolean isTrimmed()     { return (runState & TRIMMED) != 0; }
757  
758 +    final boolean isTerminating() {
759 +        if ((runState & TERMINATING) != 0)
760 +            return true;
761 +        if (pool.isAtLeastTerminating()) { // propagate pool state
762 +            shutdown();
763 +            return true;
764 +        }
765 +        return false;
766 +    }
767 +
768      /**
769       * Sets state to TERMINATING. Does NOT unpark or interrupt
770       * to wake up if currently blocked. Callers must do so if desired.
# Line 928 | Line 937 | public class ForkJoinWorkerThread extend
937          // currentJoin only written by this thread; only need ordered store
938          ForkJoinTask<?> prevJoin = currentJoin;
939          UNSAFE.putOrderedObject(this, currentJoinOffset, joinMe);
940 <        if (sp != base)
941 <            localHelpJoinTask(joinMe);
942 <        if (joinMe.status >= 0)
943 <            pool.awaitJoin(joinMe, this);
940 >        if (isTerminating())                // cancel if shutting down
941 >            joinMe.cancelIgnoringExceptions();
942 >        else {
943 >            if (sp != base)
944 >                localHelpJoinTask(joinMe);
945 >            if (joinMe.status >= 0)
946 >                pool.awaitJoin(joinMe, this);
947 >        }
948          UNSAFE.putOrderedObject(this, currentJoinOffset, prevJoin);
949      }
950  
# Line 969 | Line 982 | public class ForkJoinWorkerThread extend
982      }
983  
984      /**
985 <     * Unless terminating, tries to locate and help perform tasks for
986 <     * a stealer of the given task, or in turn one of its stealers.
987 <     * Traces currentSteal->currentJoin links looking for a thread
988 <     * working on a descendant of the given task and with a non-empty
989 <     * queue to steal back and execute tasks from.
985 >     * Tries to locate and help perform tasks for a stealer of the
986 >     * given task, or in turn one of its stealers.  Traces
987 >     * currentSteal->currentJoin links looking for a thread working on
988 >     * a descendant of the given task and with a non-empty queue to
989 >     * steal back and execute tasks from.
990       *
991       * The implementation is very branchy to cope with potential
992       * inconsistencies or loops encountering chains that are stale,
# Line 989 | Line 1002 | public class ForkJoinWorkerThread extend
1002          int n;
1003          if (joinMe.status < 0)                // already done
1004              return;
992        if ((runState & TERMINATING) != 0) {  // cancel if shutting down
993            joinMe.cancelIgnoringExceptions();
994            return;
995        }
1005          if ((ws = pool.workers) == null || (n = ws.length) <= 1)
1006              return;                           // need at least 2 workers
1007  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines