Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost.signals with boost.bind
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-10-14 09:37:23

Hash: SHA1

On Monday 13 October 2008 08:25 am, Sergey Kishchenko wrote:
> boost::shared_ptr<signal_type> apSig(new signal_type());
> apSig->connect(binded_func);
> (*apSig)();
> apSig.reset(new signal_type());
> boost::signals::connection con = apSig->connect(binded_func);
> std::cout<<"Connected: "<<con.connected()<<" Blocked:
> "<<con.blocked()<<"\n"; }
> Program output:
> Func::operator(42)
> Connected: 0 Blocked: 1
> Ie, if i create new signal and then try to connect to the same slot, it
> fails. If I use not boost::bind object but only boost::function as slot,
> all works ok. I can not understand, why? I used Boost 1.34.1, gcc 4.1.2

It looks like a bug to me. In boost.signals, the slot has a shared_ptr to its
signal/slot connection, which I think it uses for automatic connection
management. So it looks like it was coded under the assumption a slot object
(or any of its copies) would not be re-used with more than 1 signal. The
slot is probably (permanently) auto-disconnecting when the first signal it
was connected to is destroyed. The signals2 lib, which might get reviewed
soon if there are enough reviewers, doesn't show this problem.
Version: GnuPG v1.4.6 (GNU/Linux)


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at