6

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)

Mark
  • 2,082
  • 3
  • 17
  • 30

1 Answers1

5

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

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
marcinj
  • 48,511
  • 9
  • 79
  • 100