Shl*_*oim 3 c++ multithreading shared-ptr atomicity c++11
我知道shared_ptr在2个单独的线程中复制和重置单个是有问题的,但是2个线程试图创建同一个shared_ptr对象的副本呢.它需要同步吗?参考计数器在这里是否正常工作?
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
Run Code Online (Sandbox Code Playgroud)