QThread::start(优先级)与 Linux

QThread::start(priority) vs Linux

我在 KDE Neon 18.04(基于 Ubuntu 18.04,内核 4.15.0-46-generic)中使用一些基于 QThread 的工作线程。工作线程干扰了我的桌面应用程序,所以我决定降低它们的优先级。

QThread::start(priority) 的 Qt 文档说:

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).

阅读上述文档后,我预计优先级不会对我的 Linux 系统产生影响。我还是试了一下。你猜怎么着 - 它工作得很好。

那么,为什么 Qt 文档声明 Linux 上没有线程优先级?为什么它仍然有效?

根据您使用的 Linux/Unix/*Nix 的风格,调度程序可能支持也可能不支持它。据我所知,大多数 Linux 系统现在都支持 Qt 的大部分优先级,但不是所有的优先级。我怀疑文档说它不受支持,因此他们不需要列出支持优先级的 OS 变体和调度程序变体的每个组合以及支持哪些级别。

您可以通过使用 htoptop 并使用 awk 进行处理来验证它是否以正确的优先级创建了它:https://unix.stackexchange.com/questions/19301/what-is-a-command-to-find-priority-of-process-in-linux