boost::shared_ptr<A> g_a;
void func1(boost::shared_ptr<A> v)
{
g_a = v;
}
void func2()
{
boost::shared_ptr<A> a = g_a;
// a is good?
}
When func1() and func2() is executed from different threads, a of func2() is safe?
boost::shared_ptr<A> g_a;
void func1(boost::shared_ptr<A> v)
{
g_a = v;
}
void func2()
{
boost::shared_ptr<A> a = g_a;
// a is good?
}
When func1() and func2() is executed from different threads, a of func2() is safe?
No. There is data race. One thread writes g_a, another thread reads g_a. Sync needed.