CreateThread

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

Syntax

Copy
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 Process 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 Process 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. Currently, no other values are supported.

lpThreadId

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

Return Value

If the function succeeds, it returns a handle to the new thread. If the function fails, it returns NULL.

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 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 Header Library

eRTOS 1.0 SDK

windows.h rtkrnl.lib

See Also: