PDA

View Full Version : How to resolve QLibrary issue



lni
28th August 2014, 16:44
Hi,

I have a dll that can't re-enter, that is, it is not thread safe. But I need to call it repeatedly and it takes a lot of CPU time. So I am trying to use QtConcurrent and QLibrary.

However, QLibrary opens same dll and shares among themself. How can I make them not share?

The attached code gives same "addTo" and "getResult", and final results are wrong.

addTo = 0x7fcf487e063c, getResult = 0x7fcf487e0654
addTo = 0x7fcf487e063c, getResult = 0x7fcf487e0654
addTo = 0x7fcf487e063c, getResult = 0x7fcf487e0654
addTo = 0x7fcf487e063c, getResult = 0x7fcf487e0654
addTo = 0x7fcf487e063c, getResult = 0x7fcf487e0654

Any solution?

Thanks!

wysota
28th August 2014, 17:16
How can I make them not share?
You can't. That's the idea of having a shared library that there is one instance of it.


Any solution?
Perform calculations in separate processes or make the library re-entrant and thread-safe (the terms are not the same).

lni
28th August 2014, 20:37
You can't. That's the idea of having a shared library that there is one instance of it.


Perform calculations in separate processes or make the library re-entrant and thread-safe (the terms are not the same).

I can't change the dll codes. It is a huge messy mathematical program.

But how I can I do calculations in separate processes? If I make an exe out of it. I would have to call it 1000000 times (with initialization as well), that would be even slower...

Added after 25 minutes:

Here is my findings: for each thread, I copy the dll to a new name, open with QLibrary, then immediately delete it. The result appears to be good. See the attached codes.

Is there any potential problem here?

Thanks!

wysota
28th August 2014, 22:24
But how I can I do calculations in separate processes? If I make an exe out of it. I would have to call it 1000000 times
No, not really. You'd have to call it as many times as you want operations to run in parallel. Each such instance would do many calculations in sequence.


(with initialization as well), that would be even slower...
Did you test it?


Here is my findings: for each thread, I copy the dll to a new name, open with QLibrary, then immediately delete it. The result appears to be good. See the attached codes.
That's really... no, sorry, I just have to say it.... that's really stupid.