CreateThread

CreateThread creates a thread to execute within the address space of the calling process.

Syntax

HANDLE CreateThread(
    LPSECURITY_ATTRIBUTES lpThreadAttributes,
    DWORD StackSize,
    LPTHREAD_START_ROUTINE lpStartAddress,
    LPVOID lpParameter,
    DWORD dwCreationFlags,
    LPDWORD lpThreadId
);

Parameters

lpThreadAttributes

Ignored.

StackSize

The size, in bytes, of the stack for the new thread. If 0 is specified, the stack size defaults to 32768 bytes under RTSS or to the same size as the calling thread's stack under Windows. The stack is allocated automatically in the memory space of the process, and it is freed when the thread terminates. In the Windows environment, the stack size grows when necessary. In the RTSS environment, the stack cannot grow.

The number of bytes specified by StackSize must be available from non-paged memory in the kernel.

lpStartAddress

A pointer to the application-supplied function to be executed by the thread and represents the starting address of the thread. The function accepts a single 64-bit argument and returns a 64-bit exit value.

lpParameter

A single 32-bit parameter value passed to the thread.

CreationFlags

Additional flags that control the creation of the thread. If the CREATE_SUSPENDED flag is specified, the thread is created in a suspended state and will not run until ResumeThread is called. If this value is zero, the thread runs immediately after creation. At this time, no other values are supported.

lpThreadId

A pointer to a 64-bit variable that receives the thread identifier.

Return Value

A handle to the new thread if the function succeeds, NULL if the function fails

To get extended error information, call GetLastError.

Remarks

The new thread handle is created with full access to the new thread.

The thread execution begins at the function specified by lpStartAddress. If this function returns, the DWORD return value is used to terminate the thread in an implicit call to ExitThread.

The thread is created with a thread priority of 0.

The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle. (For threads, use CloseHandle rather than RtCloseHandle.)

ExitProcess, ExitThread, and CreateThread, as well as a process that is starting, are serialized between each other within a process. Only one of these events can happen in an address space at a time.

Requirements

Minimum Supported Version RTX64 2013
Header windows.h
Library Rtx_Rtss.lib

See Also:

CloseHandle

ExitProcess

ExitThread

ResumeThread