Hi, If I create a thread using boost::thread() library? boost::thread thrd( &DoWork ) ); How can I kill "thrd" later on? Thank you.
On 11/06/07, Meryl Silverburgh
If I create a thread using boost::thread() library?
boost::thread thrd( &DoWork ) );
How can I kill "thrd" later on?
AFAIK you can't. I think it's because there was no safe, reasonable, cross-platform interface found for doing so. Also, I expect it wouldn't behave well with destructors and exceptions. That's just a guess, though. ~ Scott
On 6/11/07, me22
On 11/06/07, Meryl Silverburgh
wrote: If I create a thread using boost::thread() library?
boost::thread thrd( &DoWork ) );
How can I kill "thrd" later on?
AFAIK you can't.
I think it's because there was no safe, reasonable, cross-platform interface found for doing so. Also, I expect it wouldn't behave well with destructors and exceptions. That's just a guess, though.
Thanks. But is there a solution for linux? I mean a safe way to kill thread on linux?
~ Scott _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Monday 11 June 2007 15:36, Meryl Silverburgh wrote:
If I create a thread using boost::thread() library?
boost::thread thrd( &DoWork ) );
How can I kill "thrd" later on?
The technique I typically use involves a "Control" object that is shared between the main thread and the thread function. The main thread can call the stop method of the control object, and the thread function periodically checks whether the stop command was issued. I have attached an example of this technique. This should be portable for any platform that can compile the Boost.Thread library. Justin
On Mon, Jun 11, 2007 at 05:36:43PM -0500, Meryl Silverburgh wrote:
Hi,
If I create a thread using boost::thread() library?
POSIX has the pthread_kill function. Install a signal handler, do your cleanup from the signal handler and call pthread_exit from there. Make sure the signal is not blocked.
participants (4)
-
KSpam
-
me22
-
Meryl Silverburgh
-
Zeljko Vrba