I\'m learning about multithreading and I wrote this code:
#include
#include
#include
#include
#i
No. The correct (and only correct in standard C++) way to terminate a thread is to return from its thread function.
std::terminate
kills your entire process. Even if it only killed the current thread (i.e. behaved like the Win32 TerminateThread
function, which you should never call!), it would not unwind the stack, not call destructors, and thus possibly leave some necessary cleanup unfinished (like releasing mutexes).
std::terminate
is meant to be used on a critical failure where your program cannot possibly continue. The message "without an active exception" is because the primary use of terminate
is to kill the program if the exception system fails, e.g. due to a nested exception, so the function by default looks for an active exception and prints information about it.