code: void discardUnusedTail()
      {
          // we guard this with the OpOrdering instead of synchronised due to potential dead-lock with CLSM.advanceAllocatingFrom()
          // this actually isn't strictly necessary, as currently all calls to discardUnusedTail occur within a block
          // already protected by this OpOrdering, but to prevent future potential mistakes, we duplicate the protection here
          // so that the contract between discardUnusedTail() and sync() is more explicit.
          try (OpOrder.Group group = appendOrder.start())
          {
              while (true)
              {
                  int prev = allocatePosition.get();
                  // we set allocatePosition past buffer.capacity() to make sure we always set discardedTailFrom
                  int next = buffer.capacity() + 1;
                  if (prev == next)
                      return;
                  if (allocatePosition.compareAndSet(prev, next))
                  {
                      discardedTailFrom = prev;
                      return;
                  }
              }
          }
      }
docs: ensures no more of this segment is writeable, by allocating any unused section at the end and marking it discarded