[boost.signals] documentation suggestion + thread-safe partial implementation
Hi, I'd like to suggest a sentence be added to the boost.signals documentation describing how to connect one signal directly to another signal. It took me a while to realize I could do things like signal.connect(boost::bind(boost::ref(otherSignal), _2)); wrapping a signal object in a boost::ref() call before passing it to boost::bind(), to get around signals being noncopyable. Before this epiphany, I kept writing trivial wrapper functions to use as slots when I wanted to connect two signals :) I imagine others who are new to boost.signals and boost in general would resort to similar tactics. By the way, I hacked up a partial implementation of boost.signals which is intended to be thread-safe, since I missed boost.signals so much in my multi-threaded code. Would anyone would be interested in this? It's just a few header files, and depends on boost (although not on boost.signals). I just did the bare minimum I need for my own use: a signal template class, signalslib::connection, and signalslib::scoped_connection. I didn't implement return values because I don't use them. I didn't implement boost::trackable because I don't see how to make automatic connection management thread-safe when a signal is connected to an object's member function. You really want to insure the slot is disconnected from the signal before the object providing the slot is destroyed. Inheriting the object from boost::trackable wouldn't seem to be good enough, since the boost::trackable destructor wouldn't get called until after the object's destructor. So you pretty much have to manually disconnect the connection at the beginning of the object's destructor. -- Frank
participants (1)
-
Frank Hess