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. Set QThread wait for unlimited amount of time

Set QThread wait for unlimited amount of time

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.6k Views
  • 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.
  • S Offline
    S Offline
    sasmaster
    wrote on last edited by
    #1

    How can I 'freeze' a thread for unlimited amount of time?
    I see both wait conditions and sleep methods accept some time amount to keep sleeping.Is the only way to set a large number for the wait time?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I would say that if you have a situation where you need to pause a thread for unknown (large) amount of time, it is better to completely stop it (exit from the event loop, using exit() function). Then start it up again, when it is needed.

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sasmaster
        wrote on last edited by
        #3

        In most cases you would be right.But I have OpenGL rendering thread with tons of stuff happening in a 'run()' method.I need to freeze the rendering until the user decides to go to the next frame.Theoretically it may never happen(the user remains on the same frame till the app exit() ) So I don't think restarting the thread for each next rendered frame is a good idea.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Do you have a loop in your run()? Then you could introduce a boolean variable, say isFrozen and set it when your thread needs to freeze. After that, you can check in your loop, whether the thread is allowed to go forward; if not - call sleep(). Not an elegant solution, perhaps, but it may work.

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sasmaster
            wrote on last edited by
            #5

            Isn't there smth like in boost wait condition lock?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Why yes, there is QWaitCondition. See "the docs":http://qt-project.org/doc/qt-5/QWaitCondition.html.

              (Z(:^

              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