Boost logo

Boost Users :

From: João Abecasis (jpabecasis_at_[hidden])
Date: 2006-02-14 19:03:58


Marc Mutz wrote:
> On Tuesday 14 February 2006 22:34, Steven Wooding wrote:
>> void MyClass::spawn_threads()
>> {
>> for ( int ii = 0; ii < num_threads; ++ii)
>> {
>> threadGroup.create_thread( boost::bind( ChildThreadFunc, _1, ii));
>> }
>> }
>>
>> void MyClass::ChildThreadFunc( int &threadNumber)
>> {
>> // Does some work
>> }
>
> C++ question. Use &MyClass::ChildThreadFunction as bind's first argument. You
> will probably also run into trouble with passing the int by reference (why?).

Because MyClass::ChildThreadFunc is run in a different thread, in a
separate timeline, and when it runs the variable ii may no longer exist (?).

That's my guess, anyway.

> Pass it by value.

That does seem more appropriate.

Regards,

João


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