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

Pot. regression 6.7 -> 6.8 QThreadPool too many thread IDs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.8.1, 6.9.0 FF
    • 6.8.0
    • Core: Threads
    • None
    • Windows
    • c57027199 (dev), d6c592aa2 (6.8), 4678d96d8 (dev), 1487d7edb (6.8)

      I observe a behavior change in 6.8.0: Despite setting setExpiryTimeout(-1) on QThreadPool, QThread::currentThreadId() returns more different IDs than maxThreadCount() would allow. Short program for testing:

      #include <QCoreApplication>
      #include <QThreadPool>
      #include "qmutex.h"
      #include "qtimer.h"
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QThreadPool::globalInstance()->setExpiryTimeout(-1);
          QSet<int64_t> threadids;
          QMutex mutex;
          QTimer t;
          QObject::connect(&t,&QTimer::timeout,&t,[&threadids, &mutex]() {
              for(int i=0;i<10000;++i) {
                  QThreadPool::globalInstance()->start([&threadids, &mutex]() {
                      QMutexLocker locker(&mutex);
                      threadids.insert(reinterpret_cast<int64_t>(QThread::currentThreadId()));
                      qDebug()<<threadids.size();
                  });
              }
          });
          t.start(1000);
      
      
          return   a.exec();
      }
      
        

      when running using Qt 6.7.3, the size of threadids does not exceed max threads (as desired), but it does when using Qt 6.8.0

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

            thiago Thiago Macieira
            stoeckerb Bernhard Stöcker
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes