protected boolean tryReleaseShared(int releases) { // Decrement count; signal when transition to zero for (;;) { int c = getState(); if (c == 0) return false; int nextc = c-1; if (compareAndSetState(c, nextc)) return nextc == 0; } } }
//先看构造函数 public CountDownLatch(int count) { if (count < 0) throw new IllegalArgumentException("count < 0"); //初始化sync. this.sync = new Sync(count); }
//阻塞当前线程 public void await() throws InterruptedException { sync.acquireSharedInterruptibly(1); }