参数说明
hThread 要设置的线程句柄
nPriority 优先级别参数 可设置为一下参数
THREAD_PRIORITY_ABOVE_NORMAL 比一般优先级高一个等级
THREAD_PRIORITY_BELOW_NORMAL 比一般低一个等级
THREAD_PRIORITY_HIGHEST 比一般高2个等级(最高)
THREAD_PRIORITY_IDLE 空闲
THREAD_PRIORITY_LOWEST 比一般低2个等级(最低)
THREAD_PRIORITY_NORMAL 一般等级
THREAD_PRIORITY_TIME_CRITICAL 实时
#include <Windows.h>
#include <iostream>
using namespace std;
DWORD WINAPI ThreadNormal(LPVOID lpParam)
{
int i=0;
while(i++ < 10)
cout<<"Normal Thread is running"<<endl;
return 0;
}
DWORD WINAPI ThreadAboveNormal(LPVOID lpParam)
{
int i=0;
while(i++ < 10)
cout<<"Above Normal Thread is running"<<endl;
return 0;
}
int main()
{
DWORD dwThreadID;
HANDLE hThread[2];
//Create a above Normal Thread
hThread[0] = CreateThread(NULL,0,ThreadAboveNormal,NULL,CREATE_SUSPENDED,&dwThreadID);
//set priority is above normal
SetThreadPriority(hThread[0],THREAD_PRIORITY_ABOVE_NORMAL);
//resume thread
ResumeThread(hThread[0]);
//Create a Normal Thread
hThread[1] = CreateThread(NULL,0,ThreadNormal,NULL,0,&dwThreadID);
//wait two
WaitForMultipleObjects(2,hThread,TRUE,INFINITE);
//close thread
CloseHandle(hThread[0]);
CloseHandle(hThread[1]);
return 0;
}