Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-96873

Calling QThread::start() and QThread::wait() repeatedly causes a crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 6.2.0 RC2, 6.3
    • Core: Threads
    • None
    • Linux/X11

    Description

      Running a program that creates a thread and then calls start() and wait() in a loop causes the following error on Linux:

      terminate called after throwing an instance of 'std::future_error'
        what():  std::future_error: No associated state
      

      Here is the program:

      #include <QCoreApplication>
      #include <QThread>
      #include <QTimer>
      
      static void startAndWaitForever()
      {
          QThread *thread = QThread::create([](){ });
      
          for (;;) {
              thread->start();
              Q_ASSERT(thread->wait());
          }
      };
      
      int main(int argc, char **argv) {
          QCoreApplication app(argc, argv);
      
          QTimer::singleShot(0, startAndWaitForever);
          return app.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            ievgenii.meshcheriakov Ievgenii Meshcheriakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes