Prior to C++20 a std::shared_ptr<T>
could be accessed without synchronization via its methods, or atomically using std::atomic_... functions.
In C++20, these functions are deprecated, and instead one must use the partial template specialization of std::atomic
for std::shared_ptr<T>
.
At the same time std::atomic_ref
class template does not seem to have partial specialization for std::shared_ptr<T>
, and std::atomic_ref<std::shared_ptr<T>>
fails to compile with the error:
atomic_ref<T> requires T to be trivially copyable
Does it mean that one cannot use one std::shared_ptr<T>
-like object in C++20 both atomically and without synchronization (in the places where it is safe)?
And the usage of only atomic operations seems too ineffective where they can be avoided, because any atomic load access returns a copy of shared pointer with appropriate increase of use count in the control block.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745256676a4618999.html
评论列表(0条)