CreateThread
CreateThread creates a thread to execute within the address space of the calling process.
Syntax
HANDLE CreateThread(
[in, optional] LPSECURITY_ATTRIBUTES lpThreadAttributes,
[in] DWORD StackSize,
[in] LPTHREAD_START_ROUTINE lpStartAddress,
[in, optional] LPVOID lpParameter,
[in] DWORD dwCreationFlags,
[out, optional] LPDWORD lpThreadId
);
Parameters
[in, optional] lpThreadAttributes
Ignored.
[in] StackSize
The size, in bytes, of the stack for the new thread. If 0 is specified, the stack size defaults to 49,152 bytes. The stack is allocated automatically in the process's Internal MSpace, and it is freed when the thread terminates. This differs from the Windows environment, where the stack size increases as needed. In the RTSS environment, the stack cannot grow.
The number of bytes specified by StackSize must be available in the process's Internal MSpace.
[in] lpStartAddress
A pointer to the application-supplied function to be executed by the thread represents the thread's starting address. The function accepts a single 64-bit argument and returns a 64-bit exit value.
[in, optional] lpParameter
A single 32-bit parameter value passed to the thread.
[in] CreationFlags
Additional flags that control the creation of the thread. CREATE_SUSPENDED is the only flag supported by this parameter. All other flags passed in this parameter are silently ignored.
When CREATE_SUSPENDED is specified, the thread is suspended 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.
[out, optional] 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. Call GetLastError to get extended error information.
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 terminates and all handles to it are closed through a call to CloseHandle.
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.
When the thread function name parameter is NULL, CreateThread succeeds in Release and Debug build configurations but fails in RtssDebug and RtssRelease build configurations with ERROR_INVALID_PARAMETER.
Requirements
| Minimum supported version | Header | Library |
|---|---|---|
|
wRTOS 1.0 SDK |
windows.h |
wRTOS_rtss.lib |
See Also: