Boost logo

Boost Users :

From: Jonathan Biggar (jon_at_[hidden])
Date: 2008-08-16 15:27:48


Mika Heiskanen wrote:
> David Abrahams wrote:
>> on Sat Aug 16 2008, "Eduardo Panisset" <eduardo.panisset-AT-gmail.com>
>> wrote:
>>
>>> if( new_use_count == 0 )
>>> {
>>> dispose();
>>> weak_release();
>>> }
>>>
>>> How Can I ensure that the release member function wouldn't dispose a
>>> pointee
>>> more than one time ? (release executing concurrently from different
>>> shared_ptr instances)
>>
>> Because the reference count was 1, there can be only one shared_ptr
>> instance that owns the pointee. No other threads can be referencing it.
>
> But since the mutex is released, a copy could be created before the
> new_use_count test is reached?

No, because since the old reference count was 1, only the current thread
has a copy, and since the thread is busy executing this code, it can't
also be making a copy to give to another thread.

Or is it impossible to create a copy if
> use_count_ is zero?

Yes, because we're still inside the sp_counted_base::release() function.

-- 
Jon Biggar
Floorboard Software
jon_at_[hidden]
jon_at_[hidden]

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