Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the behavoir of atexit() in a dll/so loaded at runtime?

If I load a dll/so file at runtime (i.e. using LoadLibrary() or dlopen()), what is the behavior of the C++ atexit() function? Does it get called if I unload the library before the application exits? And can I expect the same behavior on all platforms? (Specifically, windows and unix-like systems)

like image 376
Mark Avatar asked Jan 01 '12 21:01

Mark


1 Answers

Under windows: when you call FreeLibrary then for each dll there will be executed atexit functions chain. It is important to note that dll's gets unloaded in unspecified order so do not add atexit handlers that depends on some other dll's globals.

Here is some more info link: http://msdn.microsoft.com/en-us/library/988ye33t.aspx

like image 63
marcinj Avatar answered Nov 12 '22 05:11

marcinj