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. QThread::Priority for QThreadPool or QRunnable?
Qt 6.11 is out! See what's new in the release blog

QThread::Priority for QThreadPool or QRunnable?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 2.0k Views 2 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by
    #1

    Hi, I have a class that contains it's own QThreadPool object and I run instances of QRunnable using this thread-pool object. In my application, there are two instances of this class and for one type I want to run the QThreadPool-QRunnable combo with QThread::HighPriority and for another instance, I want to run it with QThread::LowPriority. Is it possible?

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

      See https://bugreports.qt.io/browse/QTBUG-3481 - feel free to provide a patch, doesn't look that complicated

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

      CJhaC 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        See https://bugreports.qt.io/browse/QTBUG-3481 - feel free to provide a patch, doesn't look that complicated

        CJhaC Offline
        CJhaC Offline
        CJha
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thanks! I am not so knowledgeable in Qt/C++ to provide a patch, but if I come up with a workaround I will definitely post it here :)

        SGaistS 1 Reply Last reply
        0
        • O Offline
          O Offline
          ollarch
          wrote on last edited by
          #4

          Hi,

          Having your own class you can have a member variable to indicate the priority you want to set. The, when you want to start the Thread pool you can set the priority according to the member variable value.

          CJhaC 1 Reply Last reply
          0
          • CJhaC CJha

            @Christian-Ehrlicher Thanks! I am not so knowledgeable in Qt/C++ to provide a patch, but if I come up with a workaround I will definitely post it here :)

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            @CJha said in QThread::Priority for QThreadPool or QRunnable?:

            @Christian-Ehrlicher Thanks! I am not so knowledgeable in Qt/C++ to provide a patch, but if I come up with a workaround I will definitely post it here :)

            You do not need to have 10+ years in C++ to provide a patch. There's now one progress that you can check from the bug report. You'll see that it is not something arcane so if you would like to participate to Qt, do not hesitate to take a look at the open issues, you will likely find something suitable for you to have some fun fixing.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • O ollarch

              Hi,

              Having your own class you can have a member variable to indicate the priority you want to set. The, when you want to start the Thread pool you can set the priority according to the member variable value.

              CJhaC Offline
              CJhaC Offline
              CJha
              wrote on last edited by
              #6

              @ollarch Hi, the priority in QThreadPool::start() is only to control the run queue's order of execution, it has nothing to do with QThread::Priority as far as I can understand.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                ollarch
                wrote on last edited by ollarch
                #7

                Hi,

                You can use this to set the priority of the current thread.

                QThread::currentThread()->setPriority(QThread::HighestPriority);
                
                CJhaC 1 Reply Last reply
                1
                • O ollarch

                  Hi,

                  You can use this to set the priority of the current thread.

                  QThread::currentThread()->setPriority(QThread::HighestPriority);
                  
                  CJhaC Offline
                  CJhaC Offline
                  CJha
                  wrote on last edited by
                  #8

                  @ollarch ok, this means I will have to do it for each QRunnable after calling QThreadPool::start() because otherwise, it would set the priority of the thread that creates the QRunnable right?

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    ollarch
                    wrote on last edited by
                    #9

                    Hi,

                    Calling this in run method will be ok as the current thread is the thread executing the run method.

                    CJhaC 1 Reply Last reply
                    0
                    • O ollarch

                      Hi,

                      Calling this in run method will be ok as the current thread is the thread executing the run method.

                      CJhaC Offline
                      CJhaC Offline
                      CJha
                      wrote on last edited by
                      #10

                      @ollarch Thanks, yes this makes sense, I will try it.

                      1 Reply Last reply
                      0

                      • Login

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