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

Comparing jsr166/src/jsr166y/ForkJoinPool.java (file contents):
Revision 1.97 by jsr166, Tue Mar 15 19:47:02 2011 UTC vs.
Revision 1.101 by dl, Wed Apr 13 11:35:30 2011 UTC

# Line 762 | Line 762 | public class ForkJoinPool extends Abstra
762  
763      /**
764       * Tries to enqueue worker w in wait queue and await change in
765 <     * worker's eventCount.  If the pool is quiescent, possibly
766 <     * terminates worker upon exit.  Otherwise, before blocking,
767 <     * rescans queues to avoid missed signals.  Upon finding work,
768 <     * releases at least one worker (which may be the current
769 <     * worker). Rescans restart upon detected staleness or failure to
770 <     * release due to contention. Note the unusual conventions about
771 <     * Thread.interrupt here and elsewhere: Because interrupts are
772 <     * used solely to alert threads to check termination, which is
773 <     * checked here anyway, we clear status (using Thread.interrupted)
774 <     * before any call to park, so that park does not immediately
775 <     * return due to status being set via some other unrelated call to
776 <     * interrupt in user code.
765 >     * worker's eventCount.  If the pool is quiescent and there is
766 >     * more than one worker, possibly terminates worker upon exit.
767 >     * Otherwise, before blocking, rescans queues to avoid missed
768 >     * signals.  Upon finding work, releases at least one worker
769 >     * (which may be the current worker). Rescans restart upon
770 >     * detected staleness or failure to release due to
771 >     * contention. Note the unusual conventions about Thread.interrupt
772 >     * here and elsewhere: Because interrupts are used solely to alert
773 >     * threads to check termination, which is checked here anyway, we
774 >     * clear status (using Thread.interrupted) before any call to
775 >     * park, so that park does not immediately return due to status
776 >     * being set via some other unrelated call to interrupt in user
777 >     * code.
778       *
779       * @param w the calling worker
780       * @param c the ctl value on entry
# Line 794 | Line 795 | public class ForkJoinPool extends Abstra
795              else if (w.eventCount != v)
796                  return true;                      // update next time
797          }
798 <        if (parallelism + (int)(nc >> AC_SHIFT) == 0 &&
798 >        if ((!shutdown || !tryTerminate(false)) &&
799 >            (int)c != 0 && parallelism + (int)(nc >> AC_SHIFT) == 0 &&
800              blockedCount == 0 && quiescerCount == 0)
801              idleAwaitWork(w, nc, c, v);           // quiescent
802          for (boolean rescanned = false;;) {
# Line 864 | Line 866 | public class ForkJoinPool extends Abstra
866                  w.parked = false;
867                  if (w.eventCount != v)
868                      break;
869 <                else if (System.nanoTime() - startTime < SHRINK_RATE)
869 >                else if (System.nanoTime() - startTime <
870 >                         SHRINK_RATE - (SHRINK_RATE / 10)) // timing slop
871                      Thread.interrupted();          // spurious wakeup
872                  else if (UNSAFE.compareAndSwapLong(this, ctlOffset,
873                                                     currentCtl, prevCtl)) {
# Line 1146 | Line 1149 | public class ForkJoinPool extends Abstra
1149                          ws[k] = w;
1150                          nextWorkerIndex = k + 1;
1151                          int m = g & SMASK;
1152 <                        g = k >= m? ((m << 1) + 1) & SMASK : g + (SG_UNIT<<1);
1152 >                        g = k > m? ((m << 1) + 1) & SMASK : g + (SG_UNIT<<1);
1153                      }
1154                  } finally {
1155                      scanGuard = g;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines