Reputation: 21
As I know thread is part of process. If close process do I need close thread manually? My code:
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
I have seen example code where the close process then thread:
CloseHandle(l_processInfo.hProcess);
CloseHandle(l_processInfo.hThread);
Upvotes: 2
Views: 706
Reputation: 2130
According to How Threads are Terminated,
A thread executes until one of the following events occurs:
- The thread calls the ExitThread function.
- Any thread of the process calls the ExitProcess function.
- The thread function returns.
- Any thread calls the TerminateThread function with a handle to the thread.
- Any thread calls the TerminateProcess function with a handle to the process.
And
The TerminateThread and TerminateProcess functions should be used only in extreme circumstances, since they do not allow threads to clean up, do not notify attached DLLs, and do not free the initial stack. In addition, handles to objects owned by the thread are not closed until the process terminates.
Upvotes: 2