How to exit the thread properly when the process is terminated anormally?
When the process is terminated anormally, for instance, I have to kill the process from the task manager, the thread which is created in the process most likely won't exit properly. So leave some resources in the thread unattended. What should I do? Thanks for your inputs.
[278 byte] By [
dullboy] at [2007-11-19 22:05:38]

# 1 Re: How to exit the thread properly when the process is terminated anormally?
When a process is forcefully terminated, either through TerminateProcess or from the TaskManager, all clean up bets are off.
The system will clean up any memory contained within the process' address space, but it will not clean up any external references (such as COM references).
The reality is that this isn't something that you can fix because the system does not provide any signalling mechanism for an app that is about to be terminated. Essentially, the system just pulls the rug out from under the app, and there isn't anything you can do.
For more info, see TerminateProcess (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminateprocess.asp) in msdn.
Btw, for similar reasons, TerminateThread should be avoided as well.
Arjay at 2007-11-9 13:58:49 >
