Re: [Boost-users] Spawning a thread on a member function
Can I spawn the thread within another member function? I believe it should be not a problem. Thanks Kind regards Pshemek Przemyslaw Sliwa Global Foreign Exchange FX Risk Engine Development Merrill Lynch ( +44 (0)20 7995 4182 ) +44 (0)79 6325 2319 * Email: przemyslaw_sliwa@ml.com -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Patrick Sent: 27 January 2006 23:03 To: boost-users@lists.boost.org Subject: Re: [Boost-users] Spawning a thread on a member function You are correct the "boost::ref(*this)" is not needed. Simple(boost::bind(&Simple::run, this)) {} -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Christian Henning Sent: Friday, January 27, 2006 4:47 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Spawning a thread on a member function This is even simpler. Is there is reason for "boost::ref(*this)" ? class Simple { Simple() : th( boost::bind( run, this )) {} void run() { for(;;){ //Thread's work goes here. } } private: boost::thread th; }; _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -------------------------------------------------------- If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Click here for important additional terms relating to this e-mail. http://www.ml.com/email_terms/ --------------------------------------------------------
Of course, you could start off threads everywhere. The problem might be synchronization and knowing if a thread is terminated or not. The function join() gives you one way to wait for a thread to terminate. I usually do that in a destructor. If you have a problem you work on, I would suggest, that you name it. So, I can help you more specifically. Christian
participants (2)
-
Christian Henning
-
Sliwa, Przemyslaw (London)