Home:ALL Converter>multiple atexit handlers in different thread

multiple atexit handlers in different thread

Ask Time:2012-09-22T17:20:54         Author:Abruzzo Forte e Gentile

Json Formatter

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++.

Author:Abruzzo Forte e Gentile,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12542520/multiple-atexit-handlers-in-different-thread
Jason Merrill :

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.",