Boost logo

Boost Users :

Subject: Re: [Boost-users] Is weak_ptr lock method thread safe?
From: Andrea Galeazzi (Galeazzi_at_[hidden])
Date: 2013-04-24 10:49:01


Il 24/04/2013 8.56, Slava ha scritto:
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
So is it thread safe or not?


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