void tryExecuteThenChain()

in dispenso/detail/future_impl.h [233:249]


  void tryExecuteThenChain() {
    ThenChain* head = thenChain_.load(std::memory_order_acquire);
    // While the chain contains anything, let's try to get it and dispatch the chain.
    while (head) {
      if (thenChain_.compare_exchange_weak(head, nullptr, std::memory_order_acq_rel)) {
        // Managed to exchange with head, value of thenChain_ now points to null chain.
        // Head points to the implicit list of items to be executed.
        while (head) {
          head = head->scheduleDestroyAndGetNext();
        }
        // At this point, the list is exhausted, so we exit the outer loop too.  It would be valid
        // to get head again and try all over again, but it is guaranteed that if another link was
        // added concurrently to our dispatch, that thread will attempt to dispatch it's own chain,
        // so we just exit the loop instead.
      }
    }
  }