关于VC++多线程
											刚接触多线程,我的代码如下
程序代码:
#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 编辑 ]



											


	    

	

还没学!标记一下!										
					
	
,从外界采数据呢