Use a semaphore flag in main() that is sent by your multi threads when they finish to then allow main() to exit. This did work to stop main() from abnormally exiting by testing that semaphore flag for the value representing the multi thread had finished.