QThreadPool: fix regression with negative expiryTimeout
It's supposed to indicate a thread never expires, but following a change where it stores the expiry with chrono we no longer considered a negative expiry as 'forever', but rather it immediately expires! More directly it is because we end up calling QDeadlineTimer::setPreciseRemainingTime(0 secs, X nsecs), and it only cares about negative seconds to set Forever. There are complications to consider nsecs for this since several nanoseconds may pass between initially calling the function and assigning the values... Amends 1f2a230b898af9da73463bca27b5883d36da7a91. Fixes: QTBUG-129898 Change-Id: I9626de31810fb2751ff6d83165d7dce5258a9baf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit c57027199996d0f0d2ac8ebc4505c78afa54ab5a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
55ad2c33b1
commit
d6c592aa2f
@ -113,7 +113,12 @@ void QThreadPoolThread::run()
|
||||
manager->waitingThreads.enqueue(this);
|
||||
registerThreadInactive();
|
||||
// wait for work, exiting after the expiry timeout is reached
|
||||
runnableReady.wait(locker.mutex(), QDeadlineTimer(manager->expiryTimeout));
|
||||
QDeadlineTimer deadline;
|
||||
if (manager->expiryTimeout.count() < 0)
|
||||
deadline = QDeadlineTimer::Forever;
|
||||
else
|
||||
deadline.setRemainingTime(manager->expiryTimeout);
|
||||
runnableReady.wait(locker.mutex(), deadline);
|
||||
// this thread is about to be deleted, do not work or expire
|
||||
if (!manager->allThreads.contains(this)) {
|
||||
Q_ASSERT(manager->queue.isEmpty());
|
||||
|
@ -414,6 +414,21 @@ void tst_QThreadPool::expiryTimeout()
|
||||
|
||||
threadPool.setExpiryTimeout(expiryTimeout);
|
||||
QCOMPARE(threadPool.expiryTimeout(), expiryTimeout);
|
||||
|
||||
threadPool.waitForDone();
|
||||
// Negative times should be 'forever'
|
||||
threadPool.setExpiryTimeout(-1);
|
||||
QCOMPARE(threadPool.expiryTimeout(), -1);
|
||||
|
||||
threadPool.start(&task);
|
||||
QVERIFY(task.semaphore.tryAcquire(1, 10'000));
|
||||
QCOMPARE(task.runCount.loadRelaxed(), 3);
|
||||
firstThread = task.thread;
|
||||
|
||||
QTest::qWait(100); // Let some time elapse after the task finishes...
|
||||
|
||||
// Since the thread never expires it should still be waiting for a new task:
|
||||
QVERIFY(firstThread->isRunning());
|
||||
}
|
||||
|
||||
void tst_QThreadPool::expiryTimeoutRace() // QTBUG-3786
|
||||
|
Loading…
x
Reference in New Issue
Block a user