I need to create a multithreaded application in Qt wherein I am able to assign different thread priorities to different threads.
In general, I want each thread to follow the standard embedded "task" methaphor, where the task pends until it gets a "kick" of some form
(QWaitCondition), after data is loaded into its input queue to process. Each task will process its message(s), and then pend awaiting
another kick upon reception of more data.
Task priorities will be static.
The queues and other collections needs to be thread safe. "wysota" provided source code to a thread safe queue template in the forums.
Since I want each thread to "pend" until it has data, it would seem that I can not use the signals and slots mechanism, as I do NOT
intend to run the Qt event loop exec() in each thread. It has been conveyed that the "exec()" loop does not pend on all platforms.
To the issue of thread priority, the QThread::start() and the QThread::setPriority() methods help text indicates the following:
void QThread::start ( Priority priority = InheritPriority ) [slot]Begins execution of the thread by calling run(), which should be reimplemented in a
QThread subclass to contain your code. The operating system will schedule the thread according to the priority parameter. If the thread is already running, this function does nothing.
The effect of the priority parameter is dependent on the operating system's scheduling policy. In particular, the priority will be ignored on systems that do not support thread priorities (such as on Linux, see http://linux.die.net/man/2/sched_setscheduler for more details).
void QThread::setPriority ( Priority priority )This function sets the priority for a running thread. If the thread is not running, this function does nothing and returns immediately. Use start() to start a thread with a specific priority.
The priority argument can be any value in the QThread::Priority enum except for InheritPriorty.
The effect of the priority parameter is dependent on the operating system's scheduling policy. In particular, the priority will be ignored on systems that do not support thread priorities (such as on Linux, see http://linux.die.net/man/2/sched_setscheduler for more details).
From this information, I would observe the following:
1. It would seem then that I may need to derive from QThread for my threads if I need the ability to set thread priorities.
2. Under Linux, the Qt documentation suggests that there is no support for thread priorities under Linux.
For observation #1, this requirement of deriving from QThread would make helper classes such as QtConcurrent not a good fit for my application.
QThread class have method setPriority(), but QtConcurrent doesn’t. There is a posting available on how to make QtConcurrent accept priorities,
but the finer level of control of QThread begins to look attractive.
For observation #2, this seems to contradict what I observe in the Qt source code for Linux/Unix, and my experience with pthreads.
The following URL (circa 2007) describes problems with thread priorities under Linux.
http://lists.trolltech.com/qt-intere...ad00746-0.html
Does anybody have any recent experience with thread priorities under Linux using Qt?
Bookmarks