Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This function creates a thread to execute within the address space of the calling process.
HANDLE CreateThread( LPSECURITY_ATTRIBUTES lpThreadAttributes , DWORD dwStackSize , LPTHREAD_START_ROUTINE lpStartAddress , LPVOID lpParameter , DWORD dwCreationFlags , LPDWORD lpThreadId );
Parameters
Value | Description |
---|---|
CREATE_SUSPENDED | The thread is created in a suspended state, and will not run until the ResumeThreadfunction is called. |
0 | The thread runs immediately after creation. |
If this parameter is NULL, the thread identifier is not returned.
Return Values
A handle to the new thread indicates success. NULL indicates failure. To get extended error information, call GetLastError.
Remarks
The number of threads a process can create is limited by the available virtual memory. The number of threads that can be created depends on the default stack size. If every thread has one megabyte of stack space., you can create at most 32 threads. If you reduce the default stack size, you can create more threads. However, your application will have better performance if you create one thread per processor and build queues of requests for which the application maintains the context information. A thread would process all requests in a queue before processing requests in the next queue.
The new thread handle is created with THREAD_ALL_ACCESS to the new thread. The handle can be used in any function that requires a thread object handle.
The thread execution begins at the function specified by the lpStartAddressparameter. If this function returns, the DWORDreturn value is used to terminate the thread in an implicit call to the ExitThreadfunction. Use the GetExitCodeThreadfunction to get the thread's return value.
The CreateThreadfunction may succeed even if lpStartAddresspoints to data, code, or is not accessible. If the start address is invalid when the thread runs, an exception occurs, and the thread terminates. Thread termination due to a invalid start address is handled as an error exit for the thread's process. This behavior is similar to the asynchronous nature of CreateProcess, where the process is created even if it refers to invalid or missing dynamic-link libraries (DLLs).
The thread is created with a thread priority of THREAD_PRIORITY_NORMAL. Use the GetThreadPriorityand SetThreadPriorityfunctions to get and set the priority value of a thread.
When a thread terminates, the thread object attains a signaled state, satisfying any threads that were waiting on the object.
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.
The ExitThreadfunction, CreateThreadfunction, and a process that is starting (as the result of a call by CreateProcess) are serialized between each other within a process. Only one of these events can happen in an address space at a time. This means that the following restrictions hold:
Requirements
Runs on | Versions | Defined in | Include | Link to |
---|---|---|---|---|
Windows CE OS | 1.01 and later | Winbase.h | Coredll.lib, Nk.lib |
Note This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.
See Also
CloseHandle, CreateProcess, ExitThread, GetExitCodeThread, GetLastError, GetThreadPriority, ResumeThread, SetThreadPriority, ThreadProc