Hi,
Let me be a little more presice:
MyThread::run()
{
while(!bExit)
{
get_image_from_camera
for (int i=0; i<qNumThreads; i++)
m_qThreadList[i]->start();
for (int i=0; i<qNumThreads; i++)
m_qThreadList[i]->wait();
//Get results and emit some signal to let the GUI show results
}
}
MyThread::run()
{
while(!bExit)
{
get_image_from_camera
for (int i=0; i<qNumThreads; i++)
m_qThreadList[i]->start();
for (int i=0; i<qNumThreads; i++)
m_qThreadList[i]->wait();
//Get results and emit some signal to let the GUI show results
}
}
To copy to clipboard, switch view to plain text mode
"MyThread" is running in a loop until the user stops it.
The other Threads(ThreadList) are processing Threads that compute some image processing algorithms parallel, so I need to start them and wait for them to finish to get results.
The overhead seems to be on the thread start. The OS have to create a thread, stack, copy system variables, ...
So, my question was if I could start the threads but put them to sleep with a QWaitCondition. When the "MyThread" have captured a frame from the camera, set a boolean let the threads process it. Finally what I don't know how to wait until the threads have finished.
Something like this wastes CPU on MyThread
for (int i=0; i<qNumThreads; i++)
{
while (m_qThreadList[i]->isProcessing())
;
}
for (int i=0; i<qNumThreads; i++)
{
while (m_qThreadList[i]->isProcessing())
;
}
To copy to clipboard, switch view to plain text mode
Maybe using another QWaitCondition that the threads could call "wakeOne()" ?
for (int i=0; i<qNumThreads; i++)
{
m_qThreadList[i]->m_qWaitCondition->wait();
//Here we know that thread "i" have finished its process
}
for (int i=0; i<qNumThreads; i++)
{
m_qThreadList[i]->m_qWaitCondition->wait();
//Here we know that thread "i" have finished its process
}
To copy to clipboard, switch view to plain text mode
Could this work?
Thanks,
Bookmarks