
17 Apr
2007
17 Apr
'07
10:04 a.m.
Dizzy wrote:
Hello
struct A {}
// executes before spawning any boost threads shared_ptr<A> sp(new A()); weak_ptr<A> wp(sp);
// then in thread1 sp.reset();
// in thread thread2 shared_ptr<A> sp2(wp.lock());
Is the above code thread safe ?
Yes, it is. You are manipulating different variables in the two threads. The rules for weak_ptr are essentially the same as those for shared_ptr.