code: void drainBuffers() {
          // A mostly strict ordering is achieved by observing that each buffer
          // contains tasks in a weakly sorted order starting from the last drain.
          // The buffers can be merged into a sorted array in O(n) time by using
          // counting sort and chaining on a collision.
  
          // Moves the tasks into the output array, applies them, and updates the
          // marker for the starting order of the next drain.
          int maxTaskIndex = moveTasksFromBuffers(tasks);
          updateDrainedOrder(tasks, maxTaskIndex);
          runTasks(tasks, maxTaskIndex);
      }
docs: Drains the buffers up to the amortized threshold and applies the pending
  operations.