gpt4 book ai didi

c++ - 为处于挂起状态的线程调用 TerminateThread c++

转载 作者:搜寻专家 更新时间:2023-10-31 01:45:25 30 4
gpt4 key购买 nike

调用TerminateThread时,即使线程处于挂起状态,线程也会终止吗?

最佳答案

TerminateThread function销毁线程而不考虑其状态或可能的副作用。链接的 MSDN 页面对此进行了一些详细介绍。

TerminateThread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code. DLLs attached to the thread are not notified that the thread is terminating. The system frees the thread's initial stack.

Windows Server 2003 and Windows XP: The target thread's initial stack is not freed, causing a resource leak.

TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:

我想问你为什么要调用它,因为它绝对是关闭线程的最后手段。除非您非常幸运或非常小心,否则您的应用程序将泄漏内存和其他资源。

关于c++ - 为处于挂起状态的线程调用 TerminateThread c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22188433/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com