什么情况下使用ExitThread()比使用return 退出线程 好?
有这样的情况吗?
为什么会有ExitThread()这个函数?

解决方案 »

  1.   

    http://topic.csdn.net/u/20081007/12/f66494bd-58dd-4770-a5be-62aead8f3225.html?950423909
      

  2.   

    VOID ExitThread(DWORD dwExitCode); 
    可以给一个退出code,Use the GetExitCodeThread function to retrieve a thread's exit code. 
      

  3.   

    线程函数返回值为void时,用ExitThread,参数为线程退出吗
    其它的跟return dwExitCode;一样
      

  4.   

    ExitThread is the preferred method of exiting a thread in C code. However, in C++ code, the thread is exited before any destructors can be called or any other automatic cleanup can be performed. Therefore, in C++ code, you should return from your thread function.
      

  5.   

    通常情况下,线程创建后不是直接运行线程函数,而是先运行某个库中的代码(与创建线程的方式有关),由该代码来调用线程函数,线程函数返回后还会继续执行一些其它的代码,如果用ExitThread退出线程,就不会执行后面的代码。ExitThread通常是不建议使用的,除非有特殊的需要,例如,程序主函数返回时会结束整个进程,如果希望只退出主线程,而继续运行其它线程,就可以用ExitThread来退出主线程。
      

  6.   

    在绝大多数(超过90%)情况下你不应该调用ExitThread,因为这样你就没有机会释放你在创建线程后创建得一系列对象了。ExitThread是必须得,因为任何退出线程得最终结果都是调用这个函数,包括你return
      

  7.   

    return 比 ExitThread()更好。return只是表明你希望线程退出,当程序执行到return后,线程并不是立刻退出,它还要做一些清理工作。
    然后ExitThread()函数将使用线程立刻退出,作为线程自身,它永远无法知道自己执行到哪里,在系统内的清理工作也无法完成。一个线程在退出的时候,无论你是使用return还是_endThread(),系统都会调用ExitThread(),无过是在清理过程完成之后。因此,建议不要使用ExitThread()函数。return是最好的做法。
      

  8.   

    ok i got it
    thank you all