最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论