Another QWaitCondition error (destroyed while threads are running)
Hello,
I have seen many people face a similar problem, but none of the answers solves mine. Below is a complete minimal example that reproduces the problem.
Code:
#include <QtCore/QtConcurrentMap>
#include <vector>
void work ( double & d )
{
d = 1.;
return;
}
void main ( int argc, char ** argv )
{
std::vector<double> v(500,0.);
QtConcurrent::blockingMap(v.begin(),v.end(),work);
return;
}
Compiled with Qt 4.8.3 and Visual Studio 2010, the produced executable complains that a QWaitCondition was destroyed while threads were still waiting. What am I doing wrong? Should I upgrade Qt to fix this issue? Is there any workaround in case I can't upgrade right away?
Thank you for the time and support.
Yohann
Re: Another QWaitCondition error (destroyed while threads are running)
You could try calling waitForDone() on the global QThreadPool instance before returning from main()
Cheers,
_
Re: Another QWaitCondition error (destroyed while threads are running)
Hi,
Your suggestion works. Thank you.
Should I consider it a workaround (later versions of Qt don't/won't require this) or is it just the right thing to do?
Thank you
Re: Another QWaitCondition error (destroyed while threads are running)
You could also try instantiating a QCoreApplication before running anything on the global thread pool.
Its cleanup code might be doing something similar.
My guess is that the waitForDone() of the threadpool destructor comes too late in your case because the global instance is destroyed so close after being used.
The explicit call to waitForDone() just ensures that the pool's worker threads get stopped and removed before the application gets into that state of partial deconstruction it enters when main() ends.
Cheers,
_
Re: Another QWaitCondition error (destroyed while threads are running)