1.我几天前发布了这个问题(关于weak_ptr的线程安全),我现在有另一个相关的问题。如果我做这样的事情,会在上面的例子中引入一个竞争条件作为 g_w 吗?(我的平台是 ms vs2013)
std::weak_ptr<int> g_w;
void f3()
{
std::shared_ptr<int>l_s3 = g_w.lock(); //2. here will read g_w
if (l_s3)
{
;/.....
}
}
void f4() //f4 run in main thread
{
std::shared_ptr<int> p_s = std::make_shared<int>(1);
g_w = p_s;
std::thread th(f3); // f3 run in the other thread
th.detach();
// 1. p_s destory will motify g_w (write g_w)
}
2.据我所知,从std::tr1::shared_ptr/weak_ptr派生的std::shared_ptr/weak_ptr和从boost::shared_ptr/weak_ptr派生的std::tr1::shared_ptr/weak_ptr,在实现上有什么区别吗?特别是在线程安全方面。