
On Thu, Aug 28, 2008 at 1:54 PM, Scott McMurray <me22.ca+boost@gmail.com> wrote:
On Thu, Aug 28, 2008 at 12:27, Michael Marcin <mike.marcin@gmail.com> 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