@Override
  public void publish(long sequence, Sequence lowerCursor) {
    int counter = RETRIES;
    while (sequence - lowerCursor.get() > pendingPublication.length()) {
      if (--counter == 0) {
        if (yieldAndCheckInterrupt())
          return;
        counter = RETRIES;
      }
    }

    pendingPublication.set((int) sequence & pendingMask, sequence);

    // One of other threads has published this sequence for the current thread
    long cursorSequence = lowerCursor.get();
    if (cursorSequence >= sequence) {
      return;
    }

    long expectedSequence = Math.max(sequence - 1L, cursorSequence);
    long nextSequence = expectedSequence + 1;
    while (lowerCursor.compareAndSet(expectedSequence, nextSequence)) {
      if (Thread.interrupted())
        return;
      expectedSequence = nextSequence;
      nextSequence++;
      if (pendingPublication.get((int) nextSequence & pendingMask) 
          != nextSequence) {
        // if exceeds the capacity of pendingPublication, exit
        break;
      }
    }
  }