title: Innerprocess communication between independent DLLs
body: <p>I'm developing and maintaing a set of DLLs that are used as plugins for a host application. The host application has a plugin API which my plugins implement.
  The host application is developed by another company and I have no control over how the plugins are used: host application might load/unload any of the plugins at any time and in any order. A plugin can run in any thread and also might be called from different threads.</p>
  
  <p>I need a way for these plugins plugins to share a common resource. This resource should be initialized by the first plugin that is loaded and uninitialized by the last plugin that is unloaded. First and last might be different plugins. Thread safety is an important issue.</p>
  
  <p>You can think of this as a singleton that is shared between all the currently loaded plugins.</p>
  
  <p>A possible solution could be that all my plugins will share a common DLL that will initialize the singleton upon it's loading and destroy it when it is unloaded.
  However I would like to have my plugins self contained if at all possible, to ease the deployment on users's machines.</p>
  
  <p>Because the host application is cross-platform, the solution should be cross-platform and work in the same way on Windows, Mac OS and Linux (if at all possible). To that effect I looked at boost but was overwhelmed by the number of classes and options in the boost inter-process code.</p>
  
  <p>I do not ask for a complete coded solution, but rather an advice about the best way to approach this issue.</p>
  
  <p>More information and answers to questions:</p>
  
  <ol>
  <li><p>The issue here is that I cannot expect any help from the host application, so it does not really matter what it is. There are actually a few applications that use the plugins and so I cannot rely on any specific features of any single application.
  I can say that host application is a normal desktop application, e.g. plain old .exe on Windows, .app on Mac OS. No iOS or Andriod apps.</p></li>
  <li><p>Plugin interface is a set of functions the host can call. API is one way: host can call plugin but plugin cannot call host. Each plugin has an initialization function that the host must call one upon loading and an uninitialization the host must call once before unloading the DLL.</p></li>
  <li><p>Plugin are implemented in C++, but not C++11. Compilers are VisualStudio 2005 on Windows and Xcode 3.2 with gcc 4.2.1 on Mac.
  That said, I would like to again emphasize that I'm looking for a general design for approaching the issue not for specific code.</p></li>
  </ol>
  
  <p>Thank for any help!</p>