据我所知,线程是进程的一部分。如果关闭进程,我需要手动关闭线程吗? 我的代码:
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
我看过示例代码,其中关闭进程然后线程:
CloseHandle(l_processInfo.hProcess);
CloseHandle(l_processInfo.hThread);
最佳答案
根据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.
还有
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.
关于c++ - 当我终止进程时,它也会终止线程吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68076338/