From 451fb66212b015b44a017e05a224af2df9a95755 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 2 Apr 2021 13:48:37 -0700 Subject: [PATCH] QThreadPool: let the started thread have the same name as the pool If the pool has a name. This should make identifying threads belonging to different pools easier in process-inspection tools. Fixes: QTBUG-92004 Change-Id: Id2983978ad544ff79911fffd167225902efeb855 Reviewed-by: Samuel Gaist Reviewed-by: Oswald Buddenhagen --- src/corelib/thread/qthreadpool.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 911bf8a53a1..0c95912bc46 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -257,9 +257,15 @@ bool QThreadPoolPrivate::tooManyThreadsActive() const */ void QThreadPoolPrivate::startThread(QRunnable *runnable) { + Q_Q(QThreadPool); Q_ASSERT(runnable != nullptr); QScopedPointer thread(new QThreadPoolThread(this)); - thread->setObjectName(QLatin1String("Thread (pooled)")); + QString objectName; + if (QString myName = q->objectName(); !myName.isEmpty()) + objectName = myName; + else + objectName = QLatin1String("Thread (pooled)"); + thread->setObjectName(objectName); Q_ASSERT(!allThreads.contains(thread.data())); // if this assert hits, we have an ABA problem (deleted threads don't get removed here) allThreads.insert(thread.data()); ++activeThreads;