|
Boost Users : |
Subject: Re: [Boost-users] Is weak_ptr lock method thread safe?
From: Slava (Viatcheslav.Sysoltsev_at_[hidden])
Date: 2013-04-24 02:56:05
On Tue, 23 Apr 2013 18:25:40 +0200, Klaim - Joël Lamotte
<mjklaim_at_[hidden]> wrote:
> On Mon, Apr 22, 2013 at 10:26 AM, Andrea Galeazzi <galeazzi_at_[hidden]>
> 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
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