user4592590
user4592590

Reputation:

Is it necessary to terminate the threads when closing the application?

When my application is about to close, should the UI thread "tell" the other threads to terminate, and wait for them to do so before closing the application?

Upvotes: 0

Views: 1047

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37122

To clarify; when your main thread (the one that started with your process) returns from the WinMain function, the process will exit and all your other threads will terminate automatically.

It depends what your other threads are doing as to how important it is that you shut them down cleanly.

For example, if the other threads are potentially writing to disk, then you absolutely should shut them down cleanly. If they're just doing calculations then it probably wouldn't hurt to let them die automatically when your main thread exits.

However it's always good programming practice to clean up after yourself (free any memory allocations, etc).

Upvotes: 2

Related Questions