Daniel Szabo
Daniel Szabo

Reputation: 7281

Do unfinished threads hang around after my multi-threaded application fails?

My application starts multiple long-running functions/methods on their own threads. When one of these threads encounters an error, my program crashes (as expected). My question, though, is do all the threads spawned by the application stop executing? or do they hang around somewhere? If so, do I need to write another application to monitor them so I can kill them?

Thank you!

Upvotes: 2

Views: 298

Answers (3)

devshorts
devshorts

Reputation: 8872

If you are spawning processes from threads the processes you spawn will continue to run after the spawning process ends. You can kill the process tree in task manager and in code, but by default the spawned processes will keep running if your application ends ungracefully.

I'm assuming this is what you mean when you said

My application starts multiple long-running processes on their own threads

But maybe I'm misunderstanding what you are meaning to say

Upvotes: 2

Wiktor Zychla
Wiktor Zychla

Reputation: 48230

If the process which created all threads is killed/aborted, threads are aborted by the OS automatically. In other words: running process = at least one running thread, killed process = all threads terminated.

Upvotes: 1

Remus Rusanu
Remus Rusanu

Reputation: 294267

When a process finishes all threads contained in that process are terminated. A thread cannot exist outside of a process. Application crash = process termination.

Upvotes: 12

Related Questions