I have a doubt regarding the use of atexit in a multithreaded application.
Suppose I have the following scenario
Thread A calls atexit(handler_a)
Thread B calls atexit(handler_b)
main() calls atexit(handler_main)
Thread C calls atexit(handler_c)
....
are all the handler functions executed in a single unique thread or are they executed in separate threads?
If they do execute in a single thread (one after the other) will that thread be the main one?
I am using Linux and g++.
As rici says, atexit handlers are called from the thread that calls exit. If you want per-thread handlers, you can use a pthread_key_create destructor.