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. Why wait / waitForDone / yieldCurrentThread methods use the processor to 100%?
Forum Updated to NodeBB v4.3 + New Features

Why wait / waitForDone / yieldCurrentThread methods use the processor to 100%?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 967 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 AlekseyB
    #1

    Main- thread create worker- threads by inheritance from QThreadPool and some thread for async work by inheritance from QThread.

    From main- thread I use:
    wait()- for wait QThread- threads
    waitForDone() - for wait QThreadPool- threads

    From worker- threads i use:
    yieldCurrentThread()- for wait in current worker- thread (if main- thread create pause- signal or nothing current work)

    For example (this method execution by main- thread while waiting worker- threads):

    while(QuantityAllTasks > 0)
        {
            //process events
            QApplication::processEvents();
    
            waitForDone(300);
        }
    

    But all three methods utilization cores of my processor by 100% !!! Why they do this? While the above code hard- using my poor processor?

    jsulmJ kshegunovK 2 Replies Last reply
    0
    • A AlekseyB

      Main- thread create worker- threads by inheritance from QThreadPool and some thread for async work by inheritance from QThread.

      From main- thread I use:
      wait()- for wait QThread- threads
      waitForDone() - for wait QThreadPool- threads

      From worker- threads i use:
      yieldCurrentThread()- for wait in current worker- thread (if main- thread create pause- signal or nothing current work)

      For example (this method execution by main- thread while waiting worker- threads):

      while(QuantityAllTasks > 0)
          {
              //process events
              QApplication::processEvents();
      
              waitForDone(300);
          }
      

      But all three methods utilization cores of my processor by 100% !!! Why they do this? While the above code hard- using my poor processor?

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

      @AlekseyB What is waitForDone doing?

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

      1 Reply Last reply
      1
      • A AlekseyB

        Main- thread create worker- threads by inheritance from QThreadPool and some thread for async work by inheritance from QThread.

        From main- thread I use:
        wait()- for wait QThread- threads
        waitForDone() - for wait QThreadPool- threads

        From worker- threads i use:
        yieldCurrentThread()- for wait in current worker- thread (if main- thread create pause- signal or nothing current work)

        For example (this method execution by main- thread while waiting worker- threads):

        while(QuantityAllTasks > 0)
            {
                //process events
                QApplication::processEvents();
        
                waitForDone(300);
            }
        

        But all three methods utilization cores of my processor by 100% !!! Why they do this? While the above code hard- using my poor processor?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        @AlekseyB said in Why wait / waitForDone / yieldCurrentThread methods use the processor to 100%?:

        For example (this method execution by main- thread while waiting worker- threads):

        This is not how you wait for things. Either use a semaphore (or a wait condition) to signal the waiting thread to unblock, or you need to use one of the waitFor** that are provided for various classes. However without seeing the actual code it's rather hard to tell what exactly is going on. Where's this snippet you provided located and how does it get executed?

        PS. Please don't post duplicate threads, I'll be closing this one, and I refer you to your other posting.
        https://forum.qt.io/topic/91723/how-to-for-qthread-and-qthreadpool-objects-wait-for-thread-creation

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        3

        • Login

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