1 Attachment(s)
How to resolve QLibrary issue
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!
Re: How to resolve QLibrary issue
Quote:
Originally Posted by
lni
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.
Perform calculations in separate processes or make the library re-entrant and thread-safe (the terms are not the same).
1 Attachment(s)
Re: How to resolve QLibrary issue
Quote:
Originally Posted by
wysota
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!
Re: How to resolve QLibrary issue
Quote:
Originally Posted by
lni
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.
Quote:
(with initialization as well), that would be even slower...
Did you test it?
Quote:
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.