I have created a program that runs X number of threads which all need to be able to be closed down by the main thread. Currently I can stop the program so that each thread will be abruptly killed. I want to be able to detect the close and handle it more gracefully. To do this I want to use the join()
function, which waits for the threads to finish. The issue is that the threads don't have a set end and so calling join()
would mean that the main thread will wait forever for the threads to end.
So the question is. Is there a way to detect a join()
call in a thread and write a customized response to it?