Skip to content

A thread unsafe operation in Gauge::Change #526

@lbermes

Description

@lbermes

Hi,
getting the value and then exchanging it is not an atomic thread safe operation.
Between the load and the exchange another thread may also change the value.
Correct would be value += current;

void Gauge::Change(const double value) {
auto current = value_.load();
while (!value_.compare_exchange_weak(current, current + value))
;
}

Best regards

Lukas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions