2

I would like to be able to load multiple copies of a shared library into the same address space. I want them to not share any global variables, and I want the two copies to be unaware that the other has been loaded.

The use-case is parallel execution of a thread-unsafe library.

How can I do this

  • on Linux?
  • on OS X?
  • on Windows?
  • on *BSD?
  • on other Unix-like systems?
Demi
  • 3,535
  • 5
  • 29
  • 45

1 Answers1

3

The use-case is parallel execution of a thread-unsafe library.

Even if you manage to achieve the "not share any global variables" goal (which is hard), the library may still not work, because it could be calling into thread-unsafe routines in other libraries.

The obvious case is for the library to call strtok.

On Linux and Solaris, you could use dlmopen(LM_ID_NEWLM, ...). Man page.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362