Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Could Qt Thread be marked on one CPU?
Forum Updated to NodeBB v4.3 + New Features

Could Qt Thread be marked on one CPU?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 526 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MihanM Offline
    MihanM Offline
    Mihan
    wrote on last edited by
    #1

    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 CPU
    

    However, I still have a doubt:

    1. Could I do that in the thread or out of the thread, what about QtConcurrent::run()?

    The topic in chinese is as follow
    Chinese - 如何指定线程到某一CPU

    Hope someine help

    Best regards
    Mihan

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      No that's not possible - if you really want such specific stuff you have to use OS specific calls.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      4
      • MihanM Offline
        MihanM Offline
        Mihan
        wrote on last edited by
        #3

        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.

        JoeCFDJ 1 Reply Last reply
        0
        • MihanM Mihan

          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.

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @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

          1 Reply Last reply
          1
          • MihanM Mihan has marked this topic as solved on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved