Reputation: 13973
Why does the C++ standard include an atomic_store
or atomic_load
overload for shared_ptr
, but not weak_ptr
?
Is this just an oversight, or is there an actual reason for not providing atomic operations for weak_ptr
?
Upvotes: 8
Views: 1568
Reputation: 16980
This seems to be an oversight. There is a C++(17?) standard design proposal by Herb Sutter for atomic_shared_ptr/atomic_unique_ptr/atomic_weak_ptr, the document also explains the drawbacks of the existing approach with free funcitons atomic_load/atomic_store for shared_ptr: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4162.pdf
Upvotes: 3
Reputation: 185681
Presumably the answer is because, in order to use a weak_ptr
, you first convert it to a shared_ptr
using lock()
. Once you have that shared_ptr
you can use the atomic operations.
Upvotes: 1