Dear List members, I am trying to make use of threads within a class, but seem to be having problems with the syntax and getting it to compile. The outline of my class related to this thread issue is as follows: class Board{ public: void pressButton(int button); void boxAction(int box); private: boost::thread_group threads; }; void Board::pressButton(int button){ if(button=1){ threads.create_thread(&boxAction,1); } else ... } I have tried various different syntax within the create_thread() but have not been able to figure out from the documentation, or reading through the history of this mailing list, how to correctly do this. Any help you could give me would be greatly appreciated. Patricia Shaw
"Patricia Hazel Shaw [phs]"
class Board{ public: void pressButton(int button); void boxAction(int box); private: boost::thread_group threads; };
void Board::pressButton(int button){ if(button=1){ threads.create_thread(&boxAction,1);
create_thread() takes a single callable object as the parameter, so if you want to call a member function you must wrap it with bind: threads.create_thread(boost::bind(&Board::boxAction,this,1)); Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
create_thread() takes a single callable object as the parameter, so if you want to call a member function you must wrap it with bind:
threads.create_thread(boost::bind(&Board::boxAction,this,1));
Thank you, I came close to the right syntax at one point then, but now that works. Patricia.
Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Anthony Williams
-
Patricia Hazel Shaw [phs]