2
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?

Andrey Volk
  • 3,513
  • 2
  • 17
  • 29
chaeyk
  • 491
  • 1
  • 8
  • 20

1 Answers1

2

No. There is data race. One thread writes g_a, another thread reads g_a. Sync needed.

Andrey Volk
  • 3,513
  • 2
  • 17
  • 29