在一个循环中启动N个线程并在另一个循环中等待每个线程后,我收到消息“QWaitCondition: Destroyed while threads are still waiting” 。
这是代码:
int nb_threads = QThread::idealThreadCount();
QFuture<void> futures[nb_threads];
bool shared_boolean;
// launch threads
for(int i = 0;i<nb_threads;++i){
futures[i] = QtConcurrent::run(this,gpMainLoopMT,&shared_boolean,&next_pop_size,next_population);
}
// wait for threads to finish
for(int i = 0;i<nb_threads;++i){
futures[i].waitForFinished();
}
我只是无法弄清楚为什么会这样,而我正在等待每个线程。