다음을 통해 공유


Creating and Terminating a Thread (Windows CE 5.0)

Send Feedback

To create a thread, call the CreateThread function.

The following code example shows the CreateThread function prototype.

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

Because Windows CE does not support the lpThreadAttributes and dwStackSize parameters, you must set them to NULL or 0 (zero).

The following table describes the available CreateThread parameters.

Parameter Description
lpStartAddress Points to the start of the thread routine.
lpParameter Specifies an application-defined value that is passed to the thread routine.
dwCreationFlags Set to zero or to CREATE_SUSPENDED and/or STACK_SIZE_PARAM_IS_A_RESERVATION.
lpThreadId Points to a DWORD that receives the new thread's identifier.

If CreateThread is successful, it returns the handle to the new thread and the thread identifier.

You can also retrieve the thread identifier by calling the GetCurrentThreadId function from within the thread. In Windows CE, the value returned in GetCurrentThreadId is the actual thread handle.

You can also retrieve a handle to a thread by calling the GetCurrentThread function. This function returns a pseudo-handle to the thread that is valid only while in the thread.

If you specify CREATE_SUSPENDED in the dwCreationFlags parameter, the thread is created in a suspended state and must be resumed with a call to the ResumeThread function.

You can terminate a thread by calling ExitThread, which frees the resources that are used by a thread when they are no longer needed. Calling ExitThread for an application's primary thread causes the application to terminate.

See Also

Threads

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.