Re: How to terminate a thread from another thread?
You should use events for this.
When you want to terminate the thread, you raise an event. In your thread you periodically check if the event has been set and if so, exit the thread.
To create events, you can use CEvent (MFC) or CreateEvent (Win32 API).
Re: How to terminate a thread from another thread?
What you should do is:
1) In worker thread, waiting for an shutdown event
2) In parent thread, signal the shutdown event
3) In parent thread, wait for the handle object of the worker thread with a timeout (0-INFINITE)
4) In parent thread, if the waiting func returns timeout, kill the worker thread.
Re: How to terminate a thread from another thread?
Originally Posted by cyberninja
What you should do is:
1) In worker thread, waiting for an shutdown event
2) In parent thread, signal the shutdown event
3) In parent thread, wait for the handle object of the worker thread with a timeout (0-INFINITE)
4) In parent thread, if the waiting func returns timeout, kill the worker thread.
Besides that this is the same as described in the FAQ I mentioned...there is no need to kill the thread...if the thread handle becomes signaled the thread has been terminated already...
Ciao, Andreas
"Software is like sex, it's better when it's free." - Linus Torvalds
Bookmarks