c++ - Why is std::atomic_ref<std::shared_ptr<T>> unavailable? - Stack Overflow

Prior to C++20 a std::shared_ptr<T> could be accessed without synchronization via its methods, or

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信