cpp/memory/shared_ptr #29
Replies: 3 comments 2 replies
-
作者你好,你在该篇文章中的”线程安全性“部分写道”其实 shared_ptr 线程不安全主要来自于引用计数有并发更新的风险,当然引用计数本身也可以使用原子atomic”,“引用计数本身也可以使用原子atomic”的表述是不是不太严谨?shared_ptr的引用计数本身是原子性的,在 https://en.cppreference.com/w/cpp/memory/shared_ptr#Implementation_notes 链接中有说明,如下是原文: To satisfy thread safety requirements, the reference counters are typically incremented using an equivalent of std::atomic::fetch_add with std::memory_order_relaxed (decrementing requires stronger ordering to safely destroy the control block). 当然也许是我理解有偏差。 |
Beta Was this translation helpful? Give feedback.
-
手写shared_ptr中的赋值操作符操作中的release()是否没必要? |
Beta Was this translation helpful? Give feedback.
-
智能指针的实现中,引用计数 |
Beta Was this translation helpful? Give feedback.
-
cpp/memory/shared_ptr
编程指北: 计算机系统学习指南, 操作系统, 计算机网络, C++, Java, 算法, 数据结构
https://csguide.cn/cpp/memory/shared_ptr.html
Beta Was this translation helpful? Give feedback.
All reactions