#include <windows.h>#include <iostream.h>
DWORD WINAPI ThreadProc1(LPVOID lpPrameter);
DWORD WINAPI ThreadProc2(LPVOID lpPrameter);
int main(void)
{
HANDLE hTread1,hTread2;
hTread1 = CreateThread(NULL,0,ThreadProc1,NULL,0,NULL);
hTread2 = CreateThread(NULL,0,ThreadProc2,NULL,0,NULL);
CloseHandle(hTread1);
CloseHandle(hTread2);
cout<<"mainThread is running!"<<endl;
return 0;
}
DWORD WINAPI ThreadProc1(LPVOID lpPrameter)
{
cout<<"Thread1 is running!"<<endl;
return 0;
}
DWORD WINAPI ThreadProc2(LPVOID lpPrameter)
{
cout<<"Thread2 is running!"<<endl;
return 0
}
执行的结果让我困惑啊!
这是编译完之后第一次运行的截图!
不解有2点,1点是为什么2次运行结果不一样,第2点是我主线程那边没有使用sleep函数,照道理应该是还没来得及运行线程1和2就应该退出了,但是事实就是3个线程都运行了!
DWORD WINAPI ThreadProc1(LPVOID lpPrameter);
DWORD WINAPI ThreadProc2(LPVOID lpPrameter);
int main(void)
{
HANDLE hTread1,hTread2;
hTread1 = CreateThread(NULL,0,ThreadProc1,NULL,0,NULL);
hTread2 = CreateThread(NULL,0,ThreadProc2,NULL,0,NULL);
CloseHandle(hTread1);
CloseHandle(hTread2);
cout<<"mainThread is running!"<<endl;
return 0;
}
DWORD WINAPI ThreadProc1(LPVOID lpPrameter)
{
cout<<"Thread1 is running!"<<endl;
return 0;
}
DWORD WINAPI ThreadProc2(LPVOID lpPrameter)
{
cout<<"Thread2 is running!"<<endl;
return 0
}
执行的结果让我困惑啊!
这是编译完之后第一次运行的截图!
不解有2点,1点是为什么2次运行结果不一样,第2点是我主线程那边没有使用sleep函数,照道理应该是还没来得及运行线程1和2就应该退出了,但是事实就是3个线程都运行了!