Could Qt Thread be marked on one CPU?
-
Hi all
I want some threads could only run on one CPU so that the main thread (UI) could be smooth.
QThread::currentThreadId() //to get current tid sched_setaffinity() // to set CPUHowever, I still have a doubt:
- Could I do that in the thread or out of the thread, what about
QtConcurrent::run()?
The topic in chinese is as follow
Chinese - 如何指定线程到某一CPUHope someine help
Best regards
Mihan - Could I do that in the thread or out of the thread, what about
-
No that's not possible - if you really want such specific stuff you have to use OS specific calls.
-
-
Sorry for late.
Yes,
sched_setaffinity()is the function in Linux./*sched.h*/ /* Set the CPU affinity for a task */ extern int sched_setaffinity (__pid_t __pid, size_t __cpusetsize, const cpu_set_t *__cpuset) __THROW;but I don't know if it works well.
@Mihan said in Could Qt Thread be marked on one CPU?:
sched_setaffinity()
From its definitions it is what you need.
https://stackoverflow.com/questions/10490756/how-to-use-sched-getaffinity-and-sched-setaffinity-in-linux-from-c
https://cpp.hotexamples.com/examples/-/-/sched_setaffinity/cpp-sched_setaffinity-function-examples.html -
M Mihan has marked this topic as solved on