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. What is the QThread::wait() function for?
Forum Updated to NodeBB v4.3 + New Features

What is the QThread::wait() function for?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 559 Views 2 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.
  • M Offline
    M Offline
    mq-loser
    wrote on 17 May 2024, 09:38 last edited by
    #1

    Regarding QThread::wait(), the official documentation has a sentence that says it provides functionality similar to the POSIX pthread_join() function.

    This statement makes me wonder if wait() has a function to reclaim thread resources?

    Do I need to use wait() after a thread has finished executing? If it really does reclaim the thread's resources, then I guess I'd still need to call wait().

    Again, the official docs have a line: Instead of wait(), consider listening for the finished() signal.

    So when should I call wait() manually?

    C K 2 Replies Last reply 17 May 2024, 09:42
    0
    • M mq-loser
      17 May 2024, 09:38

      Regarding QThread::wait(), the official documentation has a sentence that says it provides functionality similar to the POSIX pthread_join() function.

      This statement makes me wonder if wait() has a function to reclaim thread resources?

      Do I need to use wait() after a thread has finished executing? If it really does reclaim the thread's resources, then I guess I'd still need to call wait().

      Again, the official docs have a line: Instead of wait(), consider listening for the finished() signal.

      So when should I call wait() manually?

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 17 May 2024, 09:42 last edited by
      #2

      @mq-loser said in What is the QThread::wait() function for?:

      This statement makes me wonder if wait() has a function to reclaim thread resources?

      Do I need to use wait() after a thread has finished executing?

      Why should you have to wait for a finished thread? wait() waits for the thread to finish in the same way pthread_join() is waiting.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • M mq-loser
        17 May 2024, 09:38

        Regarding QThread::wait(), the official documentation has a sentence that says it provides functionality similar to the POSIX pthread_join() function.

        This statement makes me wonder if wait() has a function to reclaim thread resources?

        Do I need to use wait() after a thread has finished executing? If it really does reclaim the thread's resources, then I guess I'd still need to call wait().

        Again, the official docs have a line: Instead of wait(), consider listening for the finished() signal.

        So when should I call wait() manually?

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 17 May 2024, 11:00 last edited by
        #3

        @mq-loser said in What is the QThread::wait() function for?:

        This statement makes me wonder if wait() has a function to reclaim thread resources?

        What does this mean exactly? A thread is a function (i.e. a root of a call stack), so what resources you expect wait() to "reclaim"?

        Again, the official docs have a line: Instead of wait(), consider listening for the finished() signal.
        So when should I call wait() manually?

        You have to call wait() before the QThread destructor is run, so you can be sure that the thread has exited before internal cleanup can be done. If you want to get a notification for when the thread has exited, then you can get that by connecting to the QThread::finished signal - you may do that for example to clean up some (worker) object that you'd moved to the thread.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mq-loser
          wrote on 17 May 2024, 12:08 last edited by
          #4

          Thanks for answer.

          1 Reply Last reply
          0
          • M mq-loser has marked this topic as solved on 17 May 2024, 12:08

          1/4

          17 May 2024, 09:38

          • Login

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