// ThreadPriority.cpp : Defines the entry point for the console application.
//
#include "stdafx.h" #include <Windows.h> DWORD WINAPI ThreadIdle(LPVOID lpParam) { int i = 0; while(i < 10) { printf("Idle thread running, count = %d\n", i++); } return 0; } DWORD WINAPI ThreadNormal(LPVOID lpParam) { int i = 0; while(i < 10) { printf("Normal thread running, count = %d\n", i++); } return 0; } int _tmain(int argc, _TCHAR* argv[]) { HANDLE h[2]; DWORD dwThreadID; h[0] = ::CreateThread(NULL, NULL, ThreadIdle, NULL, CREATE_SUSPENDED, &dwThreadID); ::SetThreadPriority(h[0], THREAD_PRIORITY_IDLE); ::ResumeThread(h[0]); h[1] = ::CreateThread(NULL, NULL, ThreadNormal, NULL, 0, &dwThreadID); //::WaitForMultipleObjects(2, h, TRUE, INFINITE);.
DWORD dw = ::WaitForMultipleObjects(2, h, FALSE, 0); switch (dw) { case WAIT_FAILED: printf("wait failed!\n"); break; case WAIT_TIMEOUT: printf("wait timeout!\n"); break; case WAIT_OBJECT_0+0: printf("HANDLE h[0] is running!\n"); break; case WAIT_OBJECT_0+1: printf("HANDLE h[0] is running!\n"); break; } ::CloseHandle(h[0]); ::CloseHandle(h[1]); printf("END\n"); getchar(); return 0; } // ThreadPriority.cpp : Defines the entry point for the console application.
//
#include "stdafx.h" #include <Windows.h>
DWORD WINAPI ThreadIdle(LPVOID lpParam) { int i = 0; while(i < 10) { printf("Idle thread running, count = %d\n", i++); } return 0; }
DWORD WINAPI ThreadNormal(LPVOID lpParam) { int i = 0; while(i < 10) { printf("Normal thread running, count = %d\n", i++); } return 0; }
int _tmain(int argc, _TCHAR* argv[]) { HANDLE h[2]; DWORD dwThreadID;
h[0] = ::CreateThread(NULL, NULL, ThreadIdle, NULL, CREATE_SUSPENDED, &dwThreadID); ::SetThreadPriority(h[0], THREAD_PRIORITY_IDLE); ::ResumeThread(h[0]);
h[1] = ::CreateThread(NULL, NULL, ThreadNormal, NULL, 0, &dwThreadID);
//::WaitForMultipleObjects(2, h, TRUE, INFINITE);.
DWORD dw = ::WaitForMultipleObjects(2, h, FALSE, 0); switch (dw) { case WAIT_FAILED: printf("wait failed!\n"); break; case WAIT_TIMEOUT: printf("wait timeout!\n"); break; case WAIT_OBJECT_0+0: printf("HANDLE h[0] is running!\n"); break; case WAIT_OBJECT_0+1: printf("HANDLE h[0] is running!\n"); break; }
::CloseHandle(h[0]); ::CloseHandle(h[1]); printf("END\n"); getchar(); return 0; }
|