Trying this with boost::thread:
void MyClass::Func(int a, int b, int c, int &r) { r = a + b + c; } void MyClass::Func2(int a, int b, int c) { memberVar = a + b + c; } void MyClass::Work() { int a = 1, b = 2, c = 3; int r; boost::thread_group tg; for(int i = 0; i < 10; ++j) { boost::thread *th = new boost::thread(Func, a, b, c, r); //* error tg.add_thread(th); } tg.join_all(); } 1) I get this error on line //* of which I cannot find the reason:
error: expected primary-expression before ',' token
2) Is a reference parameter (r) a good way to get a value back from a thread? Or should I do like in Func2(), setting a member variable? (taking care of who wrote what)
3) Once I put a thread in a thread_group, how can I get values back from it? I cannot use the original pointer any more...
Thank you.
packaged_task; there's an example in this long-winded answer.&MyClass::Func. Both the class name and the ampersand are mandatory.