不退出:
1 #include <windows.h> 2 #include <process.h> 3 4 5 unsigned __stdcall _threadfun(void* pParam) 6 { 7 while(TRUE) 8 { 9 printf("hello world"); 10 } 11 } 12 13 int main(int argc, char* argv[]) 14 { 15 unsigned uThreaID; 16 _beginthreadex(NULL,0,_threadfun,NULL,NULL,&uThreaID); 17 //不調用ExitThread,主線程執行完成退出,crt會終止所有的線程,進程退出 18 //如果調用了ExitThread退出主線程,crt不會終止其他的線程,雖然主線程退出了,進程仍然在 19 ExitThread(1);//顯示調用ExitThread結束主線程,進程不退出 20 21 return 0; 22 }
退出:
1 #include <windows.h> 2 #include <process.h> 3 4 5 unsigned __stdcall _threadfun(void* pParam) 6 { 7 while(TRUE) 8 { 9 printf("hello world"); 10 } 11 } 12 13 int main(int argc, char* argv[]) 14 { 15 unsigned uThreaID; 16 _beginthreadex(NULL,0,_threadfun,NULL,NULL,&uThreaID); 17 //不調用ExitThread,主線程執行完成退出,crt會終止所有的線程,進程退出 18 //如果調用了ExitThread退出主線程,crt不會終止其他的線程,雖然主線程退出了,進程仍然在 19 //ExitThread(1);//不調用ExitThread,主線程執行完成退出,crt會終止所有的線程,進程退出
20 21 return 0; 22 }