0
Exit(0) and detach thread
Hi Let me clarify my understanding first: I have created thread objects (not the jthreads) and checker for joinable. If joinable, I try to detach them so thread works even after main thread is completed. If I want main thread to wait, I will use join() instead of detach() on thread object. This is normal flow and I believe my understanding is correct. Now, what if I have a exit(0) in main thread before join or detach is called on thread objects? Will all threads be cancelled irrespective of join or detach due to exit(0)? Will have clean exit (even though we had exit(0)) or not due to thread not joined or detached yet?
4 Respostas
+ 1
I have to try this on my ide to understand how it works. I think you're correct. exit(0) does not respect thread cleanup.
All thread regardless of what they are, mutexes etc are forcefully terminated. This means you won't have a clean exit since they've not been detached afterall
0
Thanks RuntimeTerror
How to verify if it's a clean exit or not on an ide
0
What ide do you use?
It's pretty much obvious on jetbrains clion
0
Visual studio