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. How can I manage quantity threads making by QThreadPool?
Forum Updated to NodeBB v4.3 + New Features

How can I manage quantity threads making by QThreadPool?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.3k 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.
  • A Offline
    A Offline
    AlekseyB
    wrote on last edited by
    #1

    I have i3-4130 processor and due to hyper- threading IdealThreadCount in my case is 4. I tried use:

    setMaxThreadCount(2);
    or
    Tasks.reserveThread();
    Tasks.reserveThread();
    

    but it doesn't work: program use all 4 threads.
    How can I set only 2 thread?

    aha_1980A jsulmJ 2 Replies Last reply
    0
    • A AlekseyB

      I have i3-4130 processor and due to hyper- threading IdealThreadCount in my case is 4. I tried use:

      setMaxThreadCount(2);
      or
      Tasks.reserveThread();
      Tasks.reserveThread();
      

      but it doesn't work: program use all 4 threads.
      How can I set only 2 thread?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      Hi @AlekseyB,

      How can I set only 2 thread?

      According to documentation it should work with setMaxThreadCount(2)

      Which version of Qt are you using? And which platform?

      Qt has to stay free or it will die.

      A 1 Reply Last reply
      1
      • A AlekseyB

        I have i3-4130 processor and due to hyper- threading IdealThreadCount in my case is 4. I tried use:

        setMaxThreadCount(2);
        or
        Tasks.reserveThread();
        Tasks.reserveThread();
        

        but it doesn't work: program use all 4 threads.
        How can I set only 2 thread?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @AlekseyB said in How can I manage quantity threads making by QThreadPool?:

        setMaxThreadCount(2);

        Can you show how you call it?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • aha_1980A aha_1980

          Hi @AlekseyB,

          How can I set only 2 thread?

          According to documentation it should work with setMaxThreadCount(2)

          Which version of Qt are you using? And which platform?

          A Offline
          A Offline
          AlekseyB
          wrote on last edited by AlekseyB
          #4

          Which version of Qt are you using? And which platform?
          x64-5.10.0

          Can you show how you call it?

          class TaskManager: public QThreadPool
              {
                  QThreadPool* ThreadPool;
          
              public:
                  TaskManager() {ThreadPool = QThreadPool::globalInstance();}
          
                  void addTask(QRunnable* const Task_, cint Priority_ = 0) {ThreadPool->start(Task_, Priority_);}
          
                  void WaitForFinish() {while(!ThreadPool->waitForDone(500)) QApplication::processEvents();}
              };
          ...
          TaskManager Tasks;
          
          Tasks->setMaxThreadCount(2);
          //or
          Tasks.reserveThread();
          Tasks.reserveThread();
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            You are creating a new QThreadPool in which you get the global instance. Then you modify your custom thread pool but still use the unmodified global instance to start your work.

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

            A 1 Reply Last reply
            2
            • SGaistS SGaist

              Hi,

              You are creating a new QThreadPool in which you get the global instance. Then you modify your custom thread pool but still use the unmodified global instance to start your work.

              A Offline
              A Offline
              AlekseyB
              wrote on last edited by
              #6

              @SGaist
              Thenk you, now work!

              1 Reply Last reply
              1

              • Login

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