Skip to content

wait-group: Cancellation is unsafe for multiple uses of the same wait_group #39

Description

@avdgrinten

The cancellation code checks for counter > 0 to detect if a waiter is still part of the wait_group's linked list. However, that is broken if non-zero -> zero -> non-zero transitions occur.

// Relaxed since non-zero -> zero transitions cannot happen while the mutex is held.
if(wg_->ctr_.load(std::memory_order_relaxed) > 0) {
cancelled = true;
auto it = wg_->queue_.iterator_to(this);
wg_->queue_.erase(it);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions