Why wait / waitForDone / yieldCurrentThread methods use the processor to 100%?
-
Main- thread create worker- threads by inheritance from QThreadPool and some thread for async work by inheritance from QThread.
From main- thread I use:
wait()- for wait QThread- threads
waitForDone() - for wait QThreadPool- threadsFrom worker- threads i use:
yieldCurrentThread()- for wait in current worker- thread (if main- thread create pause- signal or nothing current work)For example (this method execution by main- thread while waiting worker- threads):
while(QuantityAllTasks > 0) { //process events QApplication::processEvents(); waitForDone(300); }
But all three methods utilization cores of my processor by 100% !!! Why they do this? While the above code hard- using my poor processor?
-
Main- thread create worker- threads by inheritance from QThreadPool and some thread for async work by inheritance from QThread.
From main- thread I use:
wait()- for wait QThread- threads
waitForDone() - for wait QThreadPool- threadsFrom worker- threads i use:
yieldCurrentThread()- for wait in current worker- thread (if main- thread create pause- signal or nothing current work)For example (this method execution by main- thread while waiting worker- threads):
while(QuantityAllTasks > 0) { //process events QApplication::processEvents(); waitForDone(300); }
But all three methods utilization cores of my processor by 100% !!! Why they do this? While the above code hard- using my poor processor?
-
Main- thread create worker- threads by inheritance from QThreadPool and some thread for async work by inheritance from QThread.
From main- thread I use:
wait()- for wait QThread- threads
waitForDone() - for wait QThreadPool- threadsFrom worker- threads i use:
yieldCurrentThread()- for wait in current worker- thread (if main- thread create pause- signal or nothing current work)For example (this method execution by main- thread while waiting worker- threads):
while(QuantityAllTasks > 0) { //process events QApplication::processEvents(); waitForDone(300); }
But all three methods utilization cores of my processor by 100% !!! Why they do this? While the above code hard- using my poor processor?
@AlekseyB said in Why wait / waitForDone / yieldCurrentThread methods use the processor to 100%?:
For example (this method execution by main- thread while waiting worker- threads):
This is not how you wait for things. Either use a semaphore (or a wait condition) to signal the waiting thread to unblock, or you need to use one of the
waitFor**
that are provided for various classes. However without seeing the actual code it's rather hard to tell what exactly is going on. Where's this snippet you provided located and how does it get executed?PS. Please don't post duplicate threads, I'll be closing this one, and I refer you to your other posting.
https://forum.qt.io/topic/91723/how-to-for-qthread-and-qthreadpool-objects-wait-for-thread-creation