|
Boost Users : |
Subject: Re: [Boost-users] RE : [lambda] for thread bind
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2009-09-10 17:34:58
On Thu, Sep 10, 2009 at 10:20 PM, Boost lzw <boostlzw_at_[hidden]> wrote:
>
> 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 ) );
Wrap it in a boost::ref wrapper:
boost::thread inquiry_thread(bind(&test_thread, ref(work_thread) ) );
> work_thread.join();
> inquiry_thread.join();
> return 0;
> }
>
> Thanks in advance.
>
> Robert
>
Stuart Dootson
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