Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-02-14 17:41:27


Steven Wooding wrote:
> Hi,
>
> I've had a good search on the mailing list and while some posts have
> got close to my problem and given me a few glues, my code does't quite
> work the way I want it to.
>
> My goal is to have a (non-static) class member function run in a child
> thread + passing a parameter to it. The code I've got at the moment
> goes something like this:
>
> void MyClass::spawn_threads()
> {
> for ( int ii = 0; ii < num_threads; ++ii)
> {
> threadGroup.create_thread( boost::bind( ChildThreadFunc, _1, ii));

You need

     threadGroup.create_thread( boost::bind( &MyClass::ChildThreadFunc,
this, ii ) );

here.

> }
> }
>
> void MyClass::ChildThreadFunc( int &threadNumber)
> {
> // Does some work
> }


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