Thanks. bind(&test_thread, s) works.
How can I bind one boost::thread to another boost::thread? Here is what I want to do:
void work_thread()
{
cout << "done" << endl;
}
void test_thread(boost::thread& t)
{
while (t.joinable())
{
// do sth.
this_thread::sleep(seconds(2));
}
}
int main() {
boost::thread work_thread(work_thread);
// this line does not compile
boost::thread inquiry_thread(bind(&test_thread, work_thread ) );
work_thread.join();
inquiry_thread.join();
return 0;
}
Thanks in advance.
Robert
Boost lzw wrote:
[snip]
> but the lambda version does not compile. Why? Thanks.
> -------------------------------------
> void test_thread(std::string s)
> {
> cout << "string is" << s << endl;
> }
>
> std::string s("I am a string");
> boost::thread inquiry_thread(bind(test_thread, _1)(s) );
>
bind(test_thread, _1) creates a functor expecting one argument. Appending "(s)" right after invokes that functor, passing it s as an argument.
What you want is: bind(&test_thread, s)
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users