Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8251224

CountDownLatch has to fix count at initialization

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      Lot of times, CoutDownLatch job can't decide count, and needs to increase count dynamically during the work. It's very easy to enable it in current release of CounDownLatch.java
          public void countUp(int increment) {
            // negative count to decrease=count increament, no doReleaseShared()
              this.sync.releaseShared(increment * -1);
          }

              protected boolean tryReleaseShared(int releases) {
                  int c;
                  int nextc;
                  do {
                      c = this.getState();
                      if (c == 0 && releases > 0) { // pass negative releases
                          return false;
                      }
                      // negative releases= increase count
                      nextc = c - releases;
                  } while (!this.compareAndSetState(c, nextc));
                  
                  return nextc == 0; // return false when count increased, no doReleaseShared()

              }


        Attachments

          Activity

            People

            • Assignee:
              martin Martin Buchholz
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: