6 ms·
? https://en.cppreference.com/w/cpp/memory/weak_ptr/atomic2 https://en.cppreference.com/w/cpp/memory/weak_ptr/atomic2
by mwkaufma 1y ago
? https://en.cppreference.com/w/cpp/memory/weak_ptr/atomic2 https://en.cppreference.com/w/cpp/memory/weak_ptr/atomic2
- vlovich123 1y agoOh sure, a single weak_ptr instance itself is not safe for multiple concurrent access of non-const methods. But weak_ptr -> shared_ptr reacquisition is atomic and all control block operations are: > Note that the control block used by std::weak_ptr and std::shared_ptr is thread-safe: different non-atomic std::weak_ptr objects can be accessed using mutable operations, such as operator= or reset, simultaneously by multiple threads, even when these instances are copies or otherwise share the same control block internally. The type T may be an incomplete type. There’s no variant of shared_ptr / weak_ptr that is non atomic in the standard library AFAIK.