[smart_ptr] new shared_from_this behavior with multiple owners

I just want to point out that even with the fix that went in today, the behavior of enable_shared_from_this::shared_from_this when multiple shared_ptrs take independent ownership is inconsistent with the old behavior. The old behavior was that shared_from_this would return a shared_ptr that shared ownership with whichever shared_ptr took ownership of the object last. The new behavior is shared_from_this always returns a shared_ptr that shares ownership with the first shared_ptr to take ownership of the object. The attached example illustrates the difference when compiled against the old lib and svn trunk. I don't want to make a big deal of this, as I actually think the new behavior is more sane, but I thought I should point it out. My preferred solution would be to just point out the change in the next release notes or something like that. -- Frank

On Tue, Mar 25, 2008 at 8:55 PM, Frank Mori Hess <fmhess@speakeasy.net> wrote:
I just want to point out that even with the fix that went in today, the behavior of enable_shared_from_this::shared_from_this when multiple shared_ptrs take independent ownership is inconsistent with the old behavior. The old behavior was that shared_from_this would return a shared_ptr that shared ownership with whichever shared_ptr took ownership of the object last. The new behavior is shared_from_this always returns a shared_ptr that shares ownership with the first shared_ptr to take ownership of the object. The attached example illustrates the difference when compiled against the old lib and svn trunk.
I don't want to make a big deal of this, as I actually think the new behavior is more sane, but I thought I should point it out. My preferred solution would be to just point out the change in the next release notes or something like that.
What happens if two different deleters are used to create different shared_ptrs (on the same object) ? Does this happens with only shared_from_this inherited classes or for all types?
-- Frank
-- Felipe Magno de Almeida

On Tuesday 25 March 2008 19:58, Felipe Magno de Almeida wrote:
What happens if two different deleters are used to create different shared_ptrs (on the same object) ?
The situation I'm talking about only applies to exactly the case you describe.
Does this happens with only shared_from_this inherited classes or for all types?
Only to classes that inherit from enable_shared_from_this. -- Frank

On Tue, Mar 25, 2008 at 9:06 PM, Frank Mori Hess <fmhess@speakeasy.net> wrote:
On Tuesday 25 March 2008 19:58, Felipe Magno de Almeida wrote:
What happens if two different deleters are used to create different shared_ptrs (on the same object) ?
The situation I'm talking about only applies to exactly the case you describe.
Does this happens with only shared_from_this inherited classes or for all types?
Only to classes that inherit from enable_shared_from_this.
That seems safe. Thanks for the enable_shared_from this. I'll have to revisit some of my GUI library for workarounds for shared_from_this in constructors. That should probably remove a lot of boilerpart and unreadable code.
-- Frank
Thanks, -- Felipe Magno de Almeida
participants (2)
-
Felipe Magno de Almeida
-
Frank Mori Hess