|
Boost Users : |
Subject: Re: [Boost-users] RE : [lambda] for thread bind
From: Boost lzw (boostlzw_at_[hidden])
Date: 2009-09-10 17:20:49
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
On Thu, Sep 10, 2009 at 4:24 PM, Eric MALENFANT <
Eric.Malenfant_at_[hidden]> wrote:
> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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