[Development] Thread priority on Linux - Qt 6.9.1
Tim Blechmann
tim.blechmann at qt.io
Sat Jun 28 04:34:03 CEST 2025
>> If not, please consider this suggestion: add a method to QThread that
>> allows setting the scheduling policy, or allows setting the scheduling
>> policy and priority in a single call similar to pthread_setschedparam().
>
> Sorry, the API in question is reserved for root. Since Qt applications are
> almost always run as regular users, it would see very little use. Therefore, I
> don't think we'll add it.
>
> For the few users who need it and know what they're doing, like you, you can
> use the pthreads or Linux-specific API. You're probably doing enough code
> reviews and static analyses anyway for your application running as root that
> this is not an undue burden.
audio applications have to use rt scheduling for the audio thread(s), unless one accepts glitches.
jack or pipewire tend to grant the real-time scheduling via @audio / @pipewire groups. afaict
nowadays users can also obtain realtime scheduling via RealtimeKit (which should come with a
watchdog thread).
---
that said, real-time scheduling is always quite platform-dependent with some parametrization
involved: SCHED_FIFO/SCHED_RR use priority values, SCHED_DEADLINE and THREAD_TIME_CONSTRAINT_POLICY
use deadlines / time constraints. on windows SetThreadPriority interacts with SetPriorityClass,
though there are also specialized scheduling classes like MMCSS ...
it's a bit difficult to wrap this into a QThread API
More information about the Development
mailing list