Reputation: 12218
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 it thread safe. So i came up with the idea to just run several "copies" of the Dll independently. The easiest thing would probably be to create N renamed copies of the Dll and to load one separate Dll per thread.
Is this a possible solution? Is there a better similar way? Is there possibly some wrapper code existing ?
I know that this is not at all a good engineering solution. Please don't blame me. But it might solve a number of problems.
EDIT 2017
I've done this and it works without Problems. Great! Please note the following though:
http://msdn.microsoft.com/en-us/library/2s9wt68x%28v=vs.80%29.aspx
If a DLL declares any nonlocal data or object as __declspec( thread ), it can cause a protection fault if dynamically loaded.
Upvotes: 3
Views: 579
Reputation: 2113
We do that in some of our projects, which use the Intel JPG library for JPG compression/decompression, which is a single threaded DLL. The method works fine, though as you say is not an ideal solution as you're potentially increasing the overall memory use of your application, if the DLL in question allocates a lot of memory or uses a lot of resources.
Upvotes: 1
Reputation: 612794
That solution is perfectly possible and, in my view, is the only viable way to deal with a DLL that has global state that is not thread-safe. It's not pretty, but it does work.
Upvotes: 2