网站首页  词典首页

请输入您要查询的函数:

 

术语 terminatethread
释义 TerminateThread
语法:
C++
BOOL WINAPI TerminateThread(
__inout HANDLE hThread,
__in DWORD dwExitCode
);
TerminateThread函数
终止线程。
参数
hThread [ in , out ]
一个句柄,线程被终止。
句柄必须有THREAD_TERMINATE访问权限。有关更多信息,请参见线程安全和访问权限。
dwExitCode [in]
线程的退出代码。使用GetExitCodeThread函数检索线程的退出值。
返回值
如果函数成功,返回值为非零。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
TerminateThread是用于使一个线程退出。当发生这种情况,目标线程没有机会执行任何用户模式的代码。隶属线程DLL没有通知该线程终止。该系统释放线程的初始堆栈。
Windows Server 2003和Windows XP/2000操作系统:目标线程的初始堆栈不释放,导致资源泄漏。
TerminateThread是一个危险的功能,只应在最极端的情况下使用。您应该调用TerminateThread只有当您确切知道目标线程正在做,您控制的代码的目标线程也可能会在终止时运行的所有。例如,TerminateThread可能会导致以下问题:
如果目标线程拥有一个关键部分,关键的部分将不会被释放。
如果目标线程是从堆中分配内存,堆锁不会被释放。
如果目标线程正在执行的线程的过程中的某些要求的Kernel32当它终止时,国家可以的Kernel32不一致。
如果目标线程操纵一个共享DLL,DLL的全局状态的状态可能会破坏,影响该DLL的其他用户。
一个线程不能防范TerminateThread,比控制进入其处理其它本身。该线程处理返回的CreateThread和CreateProcess的职能有THREAD_TERMINATE访问,因此任何来电持有这些句柄可以终止您的线程之一。
如果目标线程是当这个函数被调用的进程,线程的过程,也是最后一个线程终止。
该线程对象的状态变为信号,释放任何已为线程等待其他线程终止。线程的终止由STILL_ACTIVE地位的变化对dwExitCode参数的值。
终止线程不一定从系统中删除线程对象。一个线程对象被删除时,最后一个线程句柄关闭。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
CreateProcess的
CreateThread
ExitThread
GetExitCodeThread
OpenThread
进程和线程函数
终止线程
主题
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==TerminateThread Function
Terminates a thread.
Syntax
C++
BOOL WINAPI TerminateThread(
__inout HANDLE hThread,
__in DWORD dwExitCode
);
Parameters
hThread [in, out]
A handle to the thread to be terminated.
The handle must have the THREAD_TERMINATE access right. For more information, see Thread Security and Access Rights .
dwExitCode [in]
The exit code for the thread. Use the GetExitCodeThread function to retrieve a thread's exit value.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError .
Remarks
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/2000: 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:
If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
A thread cannot protect itself against TerminateThread, other than by controlling access to its handles. The thread handle returned by the CreateThread and CreateProcess functions has THREAD_TERMINATE access, so any caller holding one of these handles can terminate your thread.
If the target thread is the last thread of a process when this function is called, the thread's process is also terminated.
The state of the thread object becomes signaled, releasing any other threads that had been waiting for the thread to terminate. The thread's termination status changes from STILL_ACTIVE to the value of the dwExitCode parameter.
Terminating a thread does not necessarily remove the thread object from the system. A thread object is deleted when the last thread handle is closed.
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
CreateProcess
CreateThread
ExitThread
GetExitCodeThread
OpenThread
Process and Thread Functions
Terminating a Thread
Threads
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms686717(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:17:24