Unsolved QThread::Priority for QThreadPool or QRunnable?
-
Hi, I have a class that contains it's own
QThreadPool
object and I run instances ofQRunnable
using this thread-pool object. In my application, there are two instances of this class and for one type I want to run theQThreadPool
-QRunnable
combo withQThread::HighPriority
and for another instance, I want to run it withQThread::LowPriority
. Is it possible? -
See https://bugreports.qt.io/browse/QTBUG-3481 - feel free to provide a patch, doesn't look that complicated
-
@Christian-Ehrlicher Thanks! I am not so knowledgeable in Qt/C++ to provide a patch, but if I come up with a workaround I will definitely post it here :)
-
Hi,
Having your own class you can have a member variable to indicate the priority you want to set. The, when you want to start the Thread pool you can set the priority according to the member variable value.
-
Hi,
@CJha said in QThread::Priority for QThreadPool or QRunnable?:
@Christian-Ehrlicher Thanks! I am not so knowledgeable in Qt/C++ to provide a patch, but if I come up with a workaround I will definitely post it here :)
You do not need to have 10+ years in C++ to provide a patch. There's now one progress that you can check from the bug report. You'll see that it is not something arcane so if you would like to participate to Qt, do not hesitate to take a look at the open issues, you will likely find something suitable for you to have some fun fixing.
-
@ollarch Hi, the priority in
QThreadPool::start()
is only to control the run queue's order of execution, it has nothing to do withQThread::Priority
as far as I can understand. -
Hi,
You can use this to set the priority of the current thread.
QThread::currentThread()->setPriority(QThread::HighestPriority);
-
@ollarch ok, this means I will have to do it for each
QRunnable
after callingQThreadPool::start()
because otherwise, it would set the priority of the thread that creates theQRunnable
right? -
Hi,
Calling this in run method will be ok as the current thread is the thread executing the run method.
-
@ollarch Thanks, yes this makes sense, I will try it.