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. QtConcurrent::map uses 100% of CPU
Qt 6.11 is out! See what's new in the release blog

QtConcurrent::map uses 100% of CPU

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 7.8k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #4

    Well, i have the function "executeAllActiveTasks" that takes a string as an argument and calls a function "requestandsaveData", this function does a snmp-get to an specific device and waits until the data is available and then saves the data in a file. The following is the code for "executeAllActiveTasks"

    @void executeAllActiveTasks(QString tname)
    {
    // double val;
    QDir path( "./databases/" );

    task *t = tasks.value(tname);
    RCDevice *d = devices.value(t->device_id());
    
           if(t!=NULL || t->status()!=STARTED || d!=NULL)
           {
               Metrics.value(t->metricType())->requestAndSaveData(d,path.absolutePath()+ QString("/") +t->taskName()+QString(".rrd"),t->metricType(),t->metricParams(),0);
           }
    

    }@

    I call that function with the following code, where "taskActivesByThread" it is a QStringList...

    @watcher.setFuture(QtConcurrent::map(tasksActivesByThread,executeAllActiveTasks));
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #5

      how long running is his task?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #6

        It is up to the size of the "taskActivesByThread" and the time to get the response of the devices, it could be one minute or even more. The application works fine, but I just want to know if any other alternative methods would produce 100% of CPU while the polling is active...

        1 Reply Last reply
        0
        • B Offline
          B Offline
          baysmith
          wrote on last edited by
          #7

          Possibly something is in an active wait state, meaning it is constantly querying to see if the results are ready.

          Nokia Certified Qt Specialist.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #8

            Well, yesss..they are waiting for the results to be ready, but just because a thread is in an active state will produce a huge increment in the cpu?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              baysmith
              wrote on last edited by
              #9

              If the thread is in an active wait state (for example waiting for a spin lock), yes. If the thread is in an inactive wait state (for example waiting for a conditional variable), no.

              What does snmp-get do and is it thread safe?

              Nokia Certified Qt Specialist.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #10

                It is thread safe...the snmp get is really a "QProcess" calling the libraries of the net-snmp, so i need the wait until the "QProcess" finish to captutre the data...

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  baysmith
                  wrote on last edited by
                  #11

                  How is it waiting for the QProcess to finish and how is it capturing the data?

                  Nokia Certified Qt Specialist.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #12

                    It's something like this...

                    @
                    QProcess snmpGet;
                    snmpGet.start(program,params);

                    if (snmpGet.waitForStarted())
                    {
                    if (!snmpGet.waitForFinished())
                    {
                    return INVALID_VALUE;
                    }
                    QString output(snmpGet.readAll());
                    //Then i have to parsing the data to obtain the data...

                    }else{

                    return INVALID_VALUE
                    }

                    @

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      baysmith
                      wrote on last edited by
                      #13

                      Nothing seems wrong with what you've described so far. If you interrupt it in a debugger when the CPU is at 100%, where does it break?

                      Nokia Certified Qt Specialist.

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #14

                        Profile it and see where the profiler says the cpu is spending all of its time.

                        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