
--- In Boost-Users@y..., Luis De la Parra <lparrab@g...> wrote:
hi all, is there a way to get a reference to the function object used by a boost::thread object??
No, and it would be very difficult to do so, since the type is lost.
when you create a new thread and feed it a function object it copies it and then starts a new thread of execution on this object.. well, I would like to send messages to the object in which the thread is running but I don't know how to do it with boos.threads...
Only by wrapping it in an adapter. The boost::ref class is a very good candidate for this. Here's an example, and I'll add this to the next release: #include <boost/ref.hpp> #include <boost/thread/thread.hpp> #include <iostream> struct thread_func { thread_func() : val(0) { } void operator()() { val = 99; } int val; }; int main() { thread_func f; boost::thread thrd(boost::ref(f)); thrd.join(); std::cout << f.val << std::endl; // should be "99" } Bill Kempf