Skip to content

Commit

Permalink
QThreadPool: let the started thread have the same name as the pool
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Oswald Buddenhagen <[email protected]>
  • Loading branch information
thiagomacieira committed Apr 3, 2021
1 parent 33786e7 commit 451fb66
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/corelib/thread/qthreadpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,15 @@ bool QThreadPoolPrivate::tooManyThreadsActive() const
*/
void QThreadPoolPrivate::startThread(QRunnable *runnable)
{
Q_Q(QThreadPool);
Q_ASSERT(runnable != nullptr);
QScopedPointer<QThreadPoolThread> 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;
Expand Down

0 comments on commit 451fb66

Please sign in to comment.