
cowwoc wrote:
Anthony Williams-4 wrote:
OK, what is your desired behaviour in these circumstances?
(1) main() thread uses at_thread_exit() and then main() returns
(2) main() thread uses at_thread_exit() and calls exit()
(3) main() thread uses at_thread_exit(). *Another* thread calls exit()
(4) *another* thread uses at_thread_exit(). main() returns
(5) *another* thread uses at_thread_exit(). main() calls exit()
(6) *another* thread uses at_thread_exit() and then calls exit()
Note that returning from main() is the same as calling exit(), and abruptly terminates all threads.
Hi Anthony,
For all cases mentioned above I would expect the shutdown hook to get invoked.
The at_thread_exit hooks are invoked in the context of the thread. When exit is called, the threads are executing something, and it is not possible to make them stop whatever they are doing in order to execute the at_thread_exit hooks (and it would be a bad idea were it possible, because the thread state could be inconsistent and cause a crash in the hook.) It's possible to execute the at_thread_exit hooks just for the thread that called exit(), but this is inconsistent and effectively duplicates atexit.