PDA

View Full Version : Another QWaitCondition error (destroyed while threads are running)



yohann.benedic
22nd June 2015, 13:39
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.



#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

anda_skoa
22nd June 2015, 14:43
You could try calling waitForDone() on the global QThreadPool instance before returning from main()

Cheers,
_

yohann.benedic
22nd June 2015, 14:55
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

anda_skoa
22nd June 2015, 15:20
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,
_

yohann.benedic
22nd June 2015, 15:39
Ok, thank you again.