有多线程。有 CreateThread(),SuspendThread(),ResumeThread(),
WaitForSingleObject(),等许多函数可用。
简单的例子,建2个,运行2个 (MS VC++ 6.0):
#include <windows.h>
#include <iostream.h>
#include <stdio.h>
DWORD WINAPI fun1(LPVOID lp);
DWORD WINAPI fun2(LPVOID lp);
int piao=1000;
HANDLE pthread1,pthread2;
main()
{
pthread1=CreateThread(0,0,fun1,0,0,0);
//pthread2=CreateThread(0 ,0,fun2,0, CREATE_SUSPENDED,0);
pthread2=CreateThread(0 ,0,fun2,0,0,0);
Sleep(3000);
CloseHandle(pthread1);
CloseHandle(pthread2);
return 0;
}
DWORD WINAPI fun1(LPVOID lp)
{
while(1)
{
if(piao>0) {
cout<< "thread-1-"<< piao--<<endl;
} else
break;
}
return 0;
}
温馨提示:内容为网友见解,仅供参考