![]() |
#2
yuccn2013-01-28 17:16
|

#include<windows.h>
#include<iostream.h>
DWORD WINAPI funproc1(LPVOID lppara);
DWORD WINAPI funproc2(LPVOID lppara);
int flag=0;
int tickets=1000;
void main()
{
HANDLE htread1;
HANDLE htread2;
htread1=CreateThread(NULL,0,funproc1,NULL,0,NULL);
htread2=CreateThread(NULL,0,funproc2,NULL,0,NULL);
CloseHandle(htread1);
CloseHandle(htread2);
while(flag<=tickets)
{
Sleep(100);
cout<<"main thread is running"<<flag<<endl;
}
cout<<"over"<<endl;
}
DWORD WINAPI funproc1(LPVOID lppara)
{
int flag1=0;
while(flag<=tickets)
{
flag1++;
cout<<"thread1 is running:"<<flag1<<endl;
}
return 0;
}
DWORD WINAPI funproc2(LPVOID lppara)
{
int flag2=0;
while(1)
{
flag2++;
cout<<"thread2 is running:"<<flag2<<endl;
}
return 0;
}
只有本站会员才能查看附件,请 登录
怎么会出现这种问题。
[ 本帖最后由 邵帅 于 2013-1-28 15:07 编辑 ]