设置线程优化级SetThreadPriority调用方法
设置线程优化级SetThreadPriority调用方法
#include "stdafx.h"
#include <Windows.h>
DWORD WINAPI ThreadProcIdle(LPVOID lpParameter)
{
for (int i=0;i<20;i++)
{
printf("I'm in thread IDLE...\n");
}
return 0;
}
DWORD WINAPI ThreadProcNormal(LPVOID lpParameter)
{
for (int i=0;i<20;i++)
{
printf("I'm in thread Normal...\n");
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwThreadIdIdle;
DWORD dwThreadIdNormal;
HANDLE hThread;
//开启两个线程
hThread = ::CreateThread(NULL,0, ThreadProcIdle, NULL, CREATE_SUSPENDED, &dwThreadIdIdle);
::SetThreadPriority(hThread,THREAD_PRIORITY_IDLE);
::ResumeThread(hThread);
hThread = ::CreateThread(NULL,0, ThreadProcNormal, NULL, CREATE_SUSPENDED, &dwThreadIdNormal);
::SetThreadPriority(hThread,THREAD_PRIORITY_NORMAL);
::ResumeThread(hThread);
//等待两个线程结束
::WaitForMultipleObjects(2,hThread,TRUE,INFINITE);
::CloseHandle(hThread);
::CloseHandle(hThread);
return 0;
}
页:
[1]