Microsoft Windows CE 3.0  

Creating and Terminating a Thread

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.

To create a thread, call the CreateThreadfunction. The following code example shows the CreateThreadfunction prototype.

lpThreadAttributes, DWORD dwStackSize, LPTHREAD_START_ROUTINE
lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD
lpThreadId );

Because Windows CE does not support the lpThreadAttributesand dwStackSizeparameters, you must set them to NULL or 0. The following table describes the remaining CreateThreadparameters.

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 0 or CREATE_SUSPENDED
lpThreadId Points to a DWORDthat receives the new thread's identifier

If CreateThreadis successful, it returns the handle to the new thread and the thread identifier. You can also retrieve the thread identifier by calling the GetCurrentThreadIdfunction from within the thread. In Windows CE, the value returned in GetCurrentThreadIdis the actual thread handle. You can also retrieve a handle to the thread by calling the GetCurrentThreadfunction. This function returns a pseudo-handle to the thread that is valid only while in the thread. If you specify CREATE_SUSPENDED in the dwCreationFlagsparameter, the thread is created in a suspended state and must be resumed with a call to the ResumeThreadfunction.

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 ExitThreadfor an application's primary thread causes the application to terminate.

 Last updated on Tuesday, May 18, 2004

© 2004 Microsoft Corporation. All rights reserved.