
On Tue, 23 Apr 2013 18:25:40 +0200, Klaim - Joël Lamotte
On Mon, Apr 22, 2013 at 10:26 AM, Andrea Galeazzi
wrote: In other words, is lock method atomic in respect to deference of the shared point?
Yes it is thread-safe, that's the whole point of the system: shared_ptr is implemented (in boost or std implementations) with an atomic counter used to sync the moment when the object need to be destroyed.
Sure? Looking at boost 1.53 headers I see it is not thread safe: template<class T> class weak_ptr { ... shared_ptr<T> lock() const BOOST_NOEXCEPT { return shared_ptr<T>( *this, boost::detail::sp_nothrow_tag() ); } ... } template<class T> class shared_ptr { ... template<class Y> shared_ptr( weak_ptr<Y> const & r, boost::detail::sp_nothrow_tag ) BOOST_NOEXCEPT : px( 0 ), pn( r.pn, boost::detail::sp_nothrow_tag() ) { if( !pn.empty() ) { px = r.px; } } ... } -- Slava