Microsoft Docs

ExitThread function

Namespace: Windows API

Header: processthreadsapi.h

Syntax

#include <processthreadsapi.h>

VOID WINAPI ExitThread(
    _In_ DWORD dwExitCode
);

Parameters

dwExitCodeThe exit code for the thread. It is available to the thread's creator via GetExitCodeThread.

Return value

This function does not return. The thread terminates and the exit code is made available to the thread’s creator.

Remarks

Example

#include <windows.h>
#include <stdio.h>

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    printf("Thread %d starting.\n", GetCurrentThreadId());
    // Perform work...
    ExitThread(0);
    // Never reached
    return 0;
}

int main(void)
{
    HANDLE hThread = CreateThread(
        NULL, 0, ThreadProc, NULL, 0, NULL);

    WaitForSingleObject(hThread, INFINITE);
    DWORD dwExitCode;
    GetExitCodeThread(hThread, &dwExitCode);
    printf("Thread exited with code %lu\\n", dwExitCode);
    CloseHandle(hThread);
    return 0;
}

See Also