code: public void signalAll()
      {
          if (!hasWaiters())
              return;
  
          // to avoid a race where the condition is not met and the woken thread managed to wait on the queue before
          // we finish signalling it all, we pick a random thread we have woken-up and hold onto it, so that if we encounter
          // it again we know we're looping. We reselect a random thread periodically, progressively less often.
          // the "correct" solution to this problem is to use a queue that permits snapshot iteration, but this solution is sufficient
          int i = 0, s = 5;
          Thread randomThread = null;
          Iterator<RegisteredSignal> iter = queue.iterator();
          while (iter.hasNext())
          {
              RegisteredSignal signal = iter.next();
              Thread signalled = signal.signal();
  
              if (signalled != null)
              {
                  if (signalled == randomThread)
                      break;
  
                  if (++i == s)
                  {
                      randomThread = signalled;
                      s <<= 1;
                  }
              }
  
              iter.remove();
          }
      }
docs: Signal all waiting threads