Книга: Microsoft Windows Embedded CE 6.0 Exam Preparation Kit
? Create a Thread
? Create a Thread
1. Using the New Project Wizard, create a new WCE Console Application named HelloWorld. Use the Typical Hello_World Application option.
2. Before the _tmain function, implement a thread function named ThreadProc:
DWORD WINAPI ThreadProc( LPVOID lpParameter) {
RETAILMSG(1,(TEXT("Thread started")));
// Suspend Thread execution for 3 seconds
Sleep(3000);
RETAILMSG(1,(TEXT("Thread Ended")));
// Return code of the thread 0,
// usually used to indicate no errors.
return 0;
}
3. By using the CreateThread function, start a thread:
HANDLE hThread = CreateThread( NULL, 0, ThreadProc, NULL, 0, NULL);
4. Check the returned value of CreateThread to verify that the thread was created successfully.
5. Wait for the thread to reach the end of the thread function and exit:
WaitForSingleObject(hThread, INFINITE);
6. Build the run-time image and download it to the target device.
7. Launch Remote Kernel Tracker and analyze how threads are managed on the system.
8. Start the HelloWorld application and follow the thread execution in the Remote Kernel Tracker window, as illustrated in Figure 3–11.
Figure 3-11 Tracking thread execution in Remote Kernel Tracker tool
- Owner match
- 6.6.4 sigwait and sigwaitinfo
- Windows API Tutorials
- 15.4.2. Debugging Multithreaded Applications
- 4.1.3. Design Issues for Threads Packages
- 7.3.2. Threads
- 9.2.5. Kernel Calls for Process Management
- 10.2.4. Thread Calls
- 7.2 Work queue manager
- Passing Parameters to Threads
- 5.2.2 Condition variable attributes
- 2.1 Creating and using threads