Boost logo

Boost Users :

Subject: Re: [Boost-users] [signals2][review] The review of the signals2 library (formerly thread_safe_signals) begins today, Nov 1st
From: Frank Mori Hess (fmhess_at_[hidden])
Date: 2009-02-22 12:53:51


On Thursday 19 February 2009, Nat Goodspeed wrote:
> Then there's the interesting question as to whether my visitor should
> complain about *any* shared_ptr in the boost::bind() object, since any
> such object becomes effectively immortal.
>
> If my visitor handles weak_ptr<anything> by passing the corresponding
> shared_ptr<anything> to slot_type::track(), then it seems reasonable to
> me to force our coders to convert any shared_ptr to weak_ptr before
> boost::bind()ing it. Does that make sense?
>
> In that case I don't really understand why my visitor would need to
> distinguish between shared_ptr<shared_trackable> and
> shared_ptr<anything_else> -- or weak_ptr<shared_trackable> and
> weak_ptr<anything_else>.
>
> Put differently, shared_trackable only seems to me to make a difference
> when the visitor encounters a plain pointer or reference to it. In that
> case, the visitor can use shared_trackable::shared_from_this() and still
> pass a shared_ptr to slot_type::track(). Am I overlooking something?

There is nothing inherently wrong with binding a shared_ptr to a slot.
I've done it intentionally myself before. It doesn't necessarily make
anything immortal. It's only a problem when the shared_ptr bound to the
slot owns an object "A", and then slot is connected to a signal which also
lives somewhere inside "A". Then you have the usual shared_ptr-cycle
problem, which can be broken by using a weak_ptr and slot::track. But you
may be binding a shared_ptr which owns an object "B" which is totally
unrelated to object containing the signal you are connecting to. Or, even
if objects "A" and "B" are the same type, the objects might for example be
arranged in some kind of tree where a shared_ptr owning child object "A"
is bound to a slot connected to a signal inside a parent object "B".




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