Skip to content

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

@avdgrinten

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions