zoukankan      html  css  js  c++  java
  • 主线程结束,进程是否退出?

    不退出:

     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 }
  • 相关阅读:
    [模板]KMP
    [BZOJ] 1833: [ZJOI2010]count 数字计数
    [BZOJ] 1563: [NOI2009]诗人小G
    [BZOJ] 2442: [Usaco2011 Open]修剪草坪
    [LOJ] #2360. 「NOIP2016」换教室
    9.18模拟赛
    [BZOJ] 2006: [NOI2010]超级钢琴
    [BZOJ] 1143: [CTSC2008]祭祀river
    [51Nod] 1218 最长递增子序列 V2
    [BZOJ] 3307: 雨天的尾巴
  • 原文地址:https://www.cnblogs.com/luzhiyuan/p/3974668.html
Copyright © 2011-2022 走看看