The best way is to get the thread you wish to 'kill' to exit. You can do this by either posting a message to the thread (assuming you've got a message loop in the thread) or by using an event/semaphore to indicate to the thread that it can die.
The other way is to call TerminateThread on the thread handle.
The difference? Method 1 will allow the thread to release any resources etc (including any 'C' runtime clearup), Method 2 will pull the plug and not allow any clearup. Our experience is to use method 1 if at all possible and only resort to method 2 if all else fails.
By the way, if you're using ANY 'C' runtime calls, you must use beginthread/endthread rather than CreateThread/ExitThread; failure to do so results in small memory leaks.
Good post, and actually it can get worse that that. Something about 'C' runtime calls locking up if the right sequence occurs. This might even be tied into beginthread vs. CreateThread and TerminateThread etc.
If your using MFC you will never know when a 'C' runtime might be used so pretty much don't use CreateThread and you might as well just exit your process as use TerminateThread.
There are several articles on MSDN about this which should be read instead of using the information I provided here.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.