TerminateThread

TerminateThread terminates a thread.

Syntax

Copy
BOOL TerminateThread(
    HANDLE hThread,
    DWORD ExitCode
);

Parameters

hThread

The thread to terminate.

ExitCode

The exit code for the thread. Use GetExitCodeThread to retrieve a thread's exit value.

Return Value

If the function succeeds, it returns TRUE, If the function fails, it returns FALSE.

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.

Note: TerminateThread is a dangerous function that should only be used in the most extreme cases.

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.

A thread cannot protect itself against TerminateThread, other than by controlling access to its handles.

If the target thread is the last thread of a process when this function is called, the thread's process is also terminated.

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.

Under Windows, when a thread's existence ends by being the target of a TerminateThread call, the thread's stack is not automatically freed, as it may contain useful debugging information. eRTOS follows this behavior, so when a Process' thread is the target of a TerminateThread call, the memory for that thread's stack will not be returned to the non-paged memory pool.

Requirements

Minimum supported version Header Library

eRTOS 1.0 SDK

windows.h rtkrnl.lib

See Also: