WIndows编程 线程优先级问题,为什么运行结果不按优先级顺序?
#include<windows.h>#include<iostream.h>DWORDWINAPIThreadIdle(LPVOIDlpParam){inti=0;wh...
#include<windows.h>
#include<iostream.h>
DWORD WINAPI ThreadIdle(LPVOID lpParam)
{
int i=0;
while(i++<10)
cout<<"Idle Thread is running"<<endl;
return 0;
}
DWORD WINAPI ThreadNormal(LPVOID lpParam)
{
int i=0;
while(i++<10)
cout<<"Normal Thread is running"<<endl;
return 0;
}
int main(int argc,char* argv[])
{
DWORD dwThreadID;
HANDLE h[2];
h[0] = ::CreateThread(NULL,0,ThreadIdle,NULL,CREATE_SUSPENDED,&dwThreadID);
::SetThreadPriority (h[0],THREAD_PRIORITY_IDLE);
::ResumeThread(h[0]);
h[1] = ::CreateThread(NULL,0,ThreadNormal,NULL,0,&dwThreadID);
::WaitForMultipleObjects(2,h,TRUE,INFINITE);
::CloseHandle(h[0]);
::CloseHandle(h[1]);
return 0;
} 展开
#include<iostream.h>
DWORD WINAPI ThreadIdle(LPVOID lpParam)
{
int i=0;
while(i++<10)
cout<<"Idle Thread is running"<<endl;
return 0;
}
DWORD WINAPI ThreadNormal(LPVOID lpParam)
{
int i=0;
while(i++<10)
cout<<"Normal Thread is running"<<endl;
return 0;
}
int main(int argc,char* argv[])
{
DWORD dwThreadID;
HANDLE h[2];
h[0] = ::CreateThread(NULL,0,ThreadIdle,NULL,CREATE_SUSPENDED,&dwThreadID);
::SetThreadPriority (h[0],THREAD_PRIORITY_IDLE);
::ResumeThread(h[0]);
h[1] = ::CreateThread(NULL,0,ThreadNormal,NULL,0,&dwThreadID);
::WaitForMultipleObjects(2,h,TRUE,INFINITE);
::CloseHandle(h[0]);
::CloseHandle(h[1]);
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询