#include <windows.h>
#include <iostream>
using namespace std;
DWORD WINAPI ThreadIdle(LPVOID lpParam)
{
int i=0;
while(i++<10)
{
cout<<"Idel 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()
{
DWORD dwThreadId;
HANDLE h[2];
h[0] = ::CreateThread(
NULL,//线程的安全性
0,//指定线程堆栈大小
ThreadIdle,//线程函数
NULL,//线程函数的参数
CREATE_SUSPENDED,//指定创建线程后是否立即启动,不立即启动
&dwThreadId//内核给新生成的线程分配的线程ID
);
::SetThreadPriority(h[0],THREAD_PRIORITY_IDLE);//把线程的属性设置为空闲,
::ResumeThread(h[0]);//恢复线程运行
h[1] = ::CreateThread(
NULL,
0,
ThreadNormal,
NULL,
0,
&dwThreadId
);//创建的线程默认优先级为Normal
::WaitForMultipleObjects(
2,//要等待内核对象的数量
h,//句柄数组
TRUE,//是否要等待所有内核对象都成为受信状态
INFINITE//无限期等待下去
);
::CloseHandle(h[0]);
::CloseHandle(h[1]);
char a;
cin >> a;
}