Is it necessary to explicitly stop all threads prior to exiting a Win32 application?

后端 未结 5 1927
[愿得一人]
[愿得一人] 2020-12-09 20:19

I have a Win32 native VC++ application that upon entering WinMain() starts a separate thread, then does some useful job while that other thread is running, then

5条回答
  •  半阙折子戏
    2020-12-09 20:49

    No, when WinMain returns, the process will be terminated, and this means all threads spawned by the process should be terminated though they might not be closed gracefully.

    However, it is possible that a primary thread is terminated while the other threads are running, resulting in the application is still running. If you call ExitThread (not exit or ExitProcess) in WinMain, and there are running threads (eventually created by the primary thread), then, you may observe this behavior. Nonetheless, just return in WinMain will call ExitProcess, and that means all threads are should be terminated.

    Correct me if it's wrong.

提交回复
热议问题