主题:[讨论]关于VC线程的问题
#include <windows.h>
#include <iostream>
using std::cout;
using std::endl;
DWORD WINAPI Fun1Proc(
LPVOID lpParameter
);
void main()
{
HANDLE hThread1;
hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL);
CloseHandle(hThread1);
cout<<"main thread is running "<<endl;
// Sleep(10);
}
DWORD WINAPI Fun1Proc(
LPVOID lpParameter
)
{
cout<<"\nthread1 is running"<<endl;
return 0;
}
当我不加Sleep(10)时,应该只有主线程执行,为什么我的两个线程都在执行?请解释一下,在此谢谢了
#include <iostream>
using std::cout;
using std::endl;
DWORD WINAPI Fun1Proc(
LPVOID lpParameter
);
void main()
{
HANDLE hThread1;
hThread1=CreateThread(NULL,0,Fun1Proc,NULL,0,NULL);
CloseHandle(hThread1);
cout<<"main thread is running "<<endl;
// Sleep(10);
}
DWORD WINAPI Fun1Proc(
LPVOID lpParameter
)
{
cout<<"\nthread1 is running"<<endl;
return 0;
}
当我不加Sleep(10)时,应该只有主线程执行,为什么我的两个线程都在执行?请解释一下,在此谢谢了