$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] weak_ptr and thread safety
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-07-22 15:27:25
Pavel Shevaev wrote:
> Guys, could you please clarify whether the following usage of weak_ptr
> is thread safe:
>
> //thread A:
> shared_ptr<Foo> p = wp.lock();
>
> //thread B:
> p.reset();
p is local to thread A, so B can't reset it.
// thread B:
wp.reset();
is not safe (A reads wp, B writes wp).
// before A and B
shared_ptr<X> p( new X );
weak_ptr<X> wp( p );
// A
shared_ptr<X> p2 = wp.lock();
// B
p.reset();
is safe (A reads wp, B writes p).