Run multiple "instances" of an unsafe Dll?

I have a dll with source code that is not thread safe yet. The DLL is quite complex and it will take quite a long time to make the thread thread safe. So I came up with the idea to just run multiple "copies" of the Dll myself. The easiest way would be to create N renamed copies of the Dll and load one separate Dll for the stream.

Is this a possible solution? Is there a better way like this? Perhaps some shell code exists?

I know this is not a good engineering solution at all. Please don't blame me. But this can solve a number of problems.

EDIT 2017

I did this and it works with no problem. Big! Please note the following:

http://msdn.microsoft.com/en-us/library/2s9wt68x%28v=vs.80%29.aspx

If the DLL declares any non-local data or object as a __declspec (stream), it may cause dynamic loading protection to fail.

+3


source to share


2 answers


This solution is perfectly possible and, in my opinion, is the only viable way to deal with a DLL with global state that is not thread safe. It's not pretty, but it works.



+2


source


We do this in some of our projects that use the Intel JPG Compression / Decompression JPG Library, which is a single threaded DLL. The method works great, although as you say it is not an ideal solution as you are potentially increasing the overall memory usage in your application if the corresponding DLL allocates a lot of memory or uses a lot of resources.



+1


source







All Articles