
On Wed, 24 Apr 2013 18:30:13 +0200, Gottlob Frege
On Mon, Apr 22, 2013 at 4:26 AM, Andrea Galeazzi
wrote: I googled this question but, although there are many discussions about it, I didn't find a clear answer. Can I assume the following piece of code to be thread safe?
shared_ptr<T> p1(new XXX); //Main threadweak_ptr<T> wp(sp); //Main thread
//Then I run two threads: A and B p1.reset(); // thread A shared_ptr<T> p2 = wp.lock(); // thread B
In other words, is lock method atomic in respect to deference of the shared point?
< snip>
What you are doing is thread-safe. It is part of the docs, can be seen in the implementation (although it is hard to see), and tons of code would break if it wasn't.
Tony
Ok, after thorough debugging session today I backup the statement above. Your specific use-case is thread-safe, at least with boost 1.53 on x86 architecture. -- Slava