いくつかのジオメトリの反復生成をスレッド化しました。レンダリングにはVTKを使用しています。各反復の後、現在の進行状況を表示(レンダリング)したいと思います。私のアプローチは、最後の2つのスレッドがQWaitConditionを待ってハングしたままになるまで期待どおりに機能します。QWaitConditionのキュー内のステータスがwokenUp(デバッガーで検査)されていても、ブロックされます。2つのスレッドの数がどういうわけか私のプロセッサの4つのコアに接続されているのではないかと思います。
簡略化したコードを以下に示します。私は何を間違っているのですか、そしてそれを修正する方法は?
class Logic
{
QMutex threadLock, renderLock;
//SOLUTION: renderLock should be per thread, not global like this!
QWaitCondition wc;
bool render;
...
}
Logic::Logic()
{
...
renderLock.lock(); //needs to be locked for QWaitCondition
}
void Logic::timerProc()
{
static int count=0;
if (render||count>10) //render wanted or not rendered in a while
{
threadLock.lock();
vtkRenderWindow->Render();
render=false;
count=0;
wc.wakeAll();
threadLock.unlock();
}
else
count++;
}
double Logic::makeMesh(int meshIndex)
{
while (notFinished)
{
...(calculate g)
threadLock.lock(); //lock scene
mesh[meshIndex]->setGeometry(g);
render=true;
threadLock.unlock();
wc.wait(&renderLock); //wait until rendered
}
return g.size;
}
void Logic::makeAllMeshes()
{
vector<QFuture<double>> r;
for (int i=0; i<meshes.size(); i++)
{
QFuture<double> future = QtConcurrent::run<double>(this, &Logic::makeMesh, i);
r.push_back(future);
}
while(any r is not finished)
QApplication::processEvents(); //give timer a chance
}