User:Kr/A DLL's Life

From Apache OpenOffice Wiki
Jump to: navigation, search

Status: draft

We are frequently facing problems with globally constructed and destructed values in C / C++, mostly leading to crashes while terminating. E.g. a shared library has a a global reference holding an object implemented in another shared library.

Suggested Solutions:

  • Don't use globals.
  • Find a pattern for globals to be usable.

There are discussions doubting the usefulness of globals, its proponents advocating the former solution suggestion, personally I think globals need to supported and must usable as expected, for the simpleness of programming. Therefore I propose the falling usage pattern for shared libraries, seemingly leading to the expected behaviour.

Dynamic Loading

  1. Dependency cycles between shared libraries need to be handled explicitly.
  2. A dynamically loaded library may not be unloaded as long as there is some reference to it's content (e.g. an objects vtable).
  3. All dynamically opened shared libraries need to be dynamically closed before "exit", in the order of dependence.


As using a link editors link facility does not give programmatical access to load and unload order, it must be ensured, that a lower dependency library does not depend on the availability of a higher dependency library:

  • If library A depends on library B, than B must not have a dependency to A during process termination.


As because of C++'s relationship to "atexit", an executable may not rely on dynamic unloading of a C++ library while using any of its globals, all of the executables globals need to be cleared (thus leading C++ libraries to be unloaded) before exiting.

Personal tools