gpt4 book ai didi

c++ - 如何降低QT Gui线程优先级?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:34:28 26 4
gpt4 key购买 nike

我正在 Linux 中设计嵌入式 QT 应用程序。我的应用程序的一部分是实时音频流,它是系统的最高优先级并且必须始终满足它的实时截止日期。我已将此线程设置为具有最高优先级的 FIFO:

schparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
pthread_setschedparam(pthread_self(),SCHED_FIFO, &schparam)

我需要我的 QT GUI 始终让出并让这个实时进程具有优先权。所以我尝试将 QT GUI 线程优先级设置为

QThread::currentThread()->setPriority(QThread::LowestPriority);

但这仍然不起作用。如果我与 GUI 交互的时间过长,我的实时音频流就会发生 Xflowing。

我需要在这里设置一些其他优先级参数吗?不幸的是,切换到实时内核不是一种选择。

最佳答案

如果您在 linux 下运行,您可以创建一个脚本并在您的应用程序启动后运行该脚本。

以下示例脚本使用 chrt 更改您的 Qt 应用线程优先级。

要使用以下脚本,您需要修改脚本以更改“your_qt_app”名称。另外,在脚本中,我为your_qt_app的线程分配了优先级为10的FIFO实时策略。您可以根据需要进行相应调整。

此外,脚本中的“ps”命令可以帮助您分析系统进程/线程的优先级。

#!/bin/bash
threads_to_change_prio="
your_qt_app
"

ps -Leo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm,args > ./threads_prio.txt
for i in $threads_to_change_prio; do
tids=$(cat ./threads_prio.txt | grep $i | awk '{print $2}');
for j in $tids; do
chrt -f -p 10 $j;
done
done

关于c++ - 如何降低QT Gui线程优先级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21918344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com