Skip to content

Memory-visibility correctness of m_mustExit  #15

@jayv

Description

@jayv

Looking at the batching code I noticed m_mustExit being a "plain" bool, which means if I understand the C++ memory model correctly that the compiler/cpu are not required to provide visibility of the changes to other threads so the background batching thread may spin indefinitely.

suggestion: switch m_mustExit to std::atomic_bool and use memory_order_acq_rel on load()/store() [2]


[1] https://github.com/vthiery/cpp-statsd-client/blob/master/include/cpp-statsd-client/UDPSender.hpp#L76
[2] https://en.cppreference.com/w/cpp/atomic/memory_order#Release-Acquire_ordering

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