MultiThread 2

来源:互联网 发布:qt高级编程 pdf下载 编辑:程序博客网 时间:2024/06/10 15:03

 #include <windows.h>
#include <iostream.h>
DWORD WINAPI Fun1Proc(LPVOID lpParameter);
void main()
{
 int index=0;
 HANDLE hThread;
 hThread=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL);
 CloseHandle(hThread);
 while (index++<100)
 {
  cout<<"main thread is running"<<endl;
 }
}
DWORD WINAPI Fun1Proc(LPVOID lpParameter)
{
 int index=0;
 while (index<100)
 {
  cout<<"thread1 is running"<<endl;
 }
 return 0;
}

和上一个帖子中的程序差别不大,在main函数和fun1proc中加入循环,示例时间片轮转的运行

 

原创粉丝点击