diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-10-21 20:28:51 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-10-22 08:25:46 +0000 |
commit | 498c2963bb84e0fa86dde365868431c8509cfe62 (patch) | |
tree | a03eb78a17193a407bec92c105d375ce0484e6e9 /src/core/jobs/qthreadpooler.cpp | |
parent | a8b8cbb9a901180c0655a9c6d8b21870657dc555 (diff) |
Prevent QThreadPool from recycling threads
Thanks to discussions with Paul Lemire and David Faure we noticed that
ThreadPooler does not change QThreadPool's default behavior of recycling
threads after 30 seconds of inactivity. For Qt3D this is disasterous.
This resulted in fairly reliable crashes when stepping through Qt3D
applications in a debugger or totally unpredictably when running
normally. In the normal run case it is unpredicable as which jobs get
scheduled to which thread is somewhat random. So if you're unlucky
you will see random crashes. If you are very lucky QThreadPool and the
system scheduler will cycle through the threads in the pool when
assigning jobs to threads, stopping the threads from being recycled.
When a thread in the pool does get recycled, the TLS for that thread
gets destroyed and when QThreadPool recreates the thread we now
potentially have a QThread with the same address but without any valid
TLS contents. Of course we rely heavily upon the contents of the TLS
by way of the frame allocator. Therefore, the thread recycling of
QThreadPool was breaking our assumption of the frame allocators living
for the duration of the application.
With this commit it is now possible to have extended debugging sessions
of Qt3D applications and it should no longer crash at random (at least
not because of this issue).
Change-Id: Id9f4f5d023fac1cda5cda436b62fb24ace40da84
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Reviewed-by: Mika Salmela <mika.salmela@theqtcompany.com>
Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/core/jobs/qthreadpooler.cpp')
-rw-r--r-- | src/core/jobs/qthreadpooler.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/core/jobs/qthreadpooler.cpp b/src/core/jobs/qthreadpooler.cpp index f38422652..94d5c04a4 100644 --- a/src/core/jobs/qthreadpooler.cpp +++ b/src/core/jobs/qthreadpooler.cpp @@ -54,6 +54,7 @@ QThreadPooler::QThreadPooler(QObject *parent) m_mutex(new QMutex(QMutex::NonRecursive)), m_taskCount(0) { + QThreadPool::globalInstance()->setExpiryTimeout(-1); } QThreadPooler::~QThreadPooler() |