Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How can I manage quantity threads making by QThreadPool?

    General and Desktop
    4
    6
    950
    Loading More Posts
    • 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
      AlekseyB last edited by

      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_1980 jsulm 2 Replies Last reply Reply Quote 0
      • aha_1980
        aha_1980 Lifetime Qt Champion @AlekseyB last edited by 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?

        Qt has to stay free or it will die.

        A 1 Reply Last reply Reply Quote 1
        • jsulm
          jsulm Lifetime Qt Champion @AlekseyB last edited by

          @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 Reply Quote 0
          • A
            AlekseyB @aha_1980 last edited by AlekseyB

            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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 2
              • A
                AlekseyB @SGaist last edited by

                @SGaist
                Thenk you, now work!

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post