Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-04-17 06:04:21


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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net