title: Loading shared library twice
body: <p>I'm trying to load a shared library in C twice:</p>
  
  <pre><code>lib1 = dlopen("mylib.so", RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
  lib2 = dlopen("mylib.so", RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
  </code></pre>
  
  <p>What I want is that lib1 and lib2 have separate address spaces so that they can do different things. Currently, the only way I can achieve this is by copying mylib so that the code looks like this:</p>
  
  <pre><code>lib1 = dlopen("mylib.so", RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
  lib2 = dlopen("mylib2.so", RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
  </code></pre>
  
  <p>In a limited scope this works fine for me. However, I have an application which uses the library a generic number of times which makes copying the library cumbersome.</p>
  
  <p>Is there a better way to have a separate address space for each time the library is loaded?</p>
  
  <p>EDIT:</p>
  
  <p>I want to load the library multiple times as my application is processing a kind of message queue. The items in the message queue refer to the name of a shared library (e.g. mylib) and contain a set of data that shall be processed by the library. I want to process the MQ in a multithreading environment, running each call to the library's method in its own thread.
  As long as the MQ contains the call to a library only once, everything is working as expected. However, when I have two items that use the same library, things start to get weird.</p>