Boost logo

Boost :

From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2008-08-28 13:05:09


On Thu, Aug 28, 2008 at 1:54 PM, Scott McMurray <me22.ca+boost_at_[hidden]> wrote:
> On Thu, Aug 28, 2008 at 12:27, Michael Marcin <mike.marcin_at_[hidden]> wrote:
>> Sebastian Redl wrote:

[snip]

>>> I think scoped_ptr should have a release(). It's technically impossible to
>>> add a useful one to the refcounted smart pointers.
>>
>> It works for refcounted smart pointers iff p.unique() == true.
>
> Which means it's likely a race condition if you try to do it in a
> multi-threaded program, because a weak_ptr could get lock()ed at any
> point.

You can use the same technique that ~shared_ptr does.
Decrement it atomically and then check the old value.

> Custom deleters also make it quite awkward to handle properly.

Why?

> Since it would require that only one pointer holds it, it seems like
> the correct way to do it is to use unique_ptr instead, which enforces
> that invariant.

True. But it might be useful when you need to comply with
an interface.

> ~ Scott

Regards,

-- 
Felipe Magno de Almeida

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk