+ 1

Detach thread exception

Do process terminate even if a thread detached (not joined) has an exception? Ideally it should not be. Right?

5th Mar 2025, 4:39 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Respuestas
+ 2
Hi Ketan, I think the behaviour is undefined, but in most implementations if a detached thread throws an exception, the whole process might actually terminate, which isn't ideal. This happens because if an exception isn't caught within the thread, it will propagate in the call stack and eventually call std::terminate(), which by default calls abord(), killing the entire process.
5th Mar 2025, 12:42 PM
Amine Laaboudi
Amine Laaboudi - avatar
+ 2
In practice, the thing (to have a detached thread throw an exception and let the process continue normally) isn't something you can count on.
5th Mar 2025, 12:45 PM
Amine Laaboudi
Amine Laaboudi - avatar
+ 1
5th Mar 2025, 2:21 PM
Ketan Lalcheta
Ketan Lalcheta - avatar