【发布时间】:2017-03-07 16:41:00
【问题描述】:
我知道在 2 个单独的线程中复制和重置单个 shared_ptr 是有问题的,但是尝试创建同一 shared_ptr 对象的副本的 2 个线程呢?需要同步吗?引用计数器在这里可以正常工作吗?
std::shared_ptr<T> global_t(new T());
// Thread 1
std::shared_ptr<T> t1(global_t);
do something with t1
// Thread 2
std::shared_ptr<T> t2(global_t);
do something with t2
【问题讨论】:
标签: c++ multithreading c++11 shared-ptr atomic