|
Boost Users : |
Subject: Re: [Boost-users] Is weak_ptr lock method thread safe?
From: Slava (Viatcheslav.Sysoltsev_at_[hidden])
Date: 2013-04-25 05:36:04
On Wed, 24 Apr 2013 18:30:13 +0200, Gottlob Frege <gottlobfrege_at_[hidden]>
wrote:
> On Mon, Apr 22, 2013 at 4:26 AM, Andrea Galeazzi <galeazzi_at_[hidden]>
> 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
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