From 914dffb9a2c1f2afc0ee3834a813f50c2cde6a82 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 27 Apr 2023 12:23:48 +1000 Subject: [PATCH] Fix deadlock when number of point cloud files loaded >= available threads This would cause multiple QgsTasks to be created, each of which uses one thread -- then if the number of tasks matches or exceeds the number of available threads, then the call to blockingMapped in QgsPointCloudStatsCalculator will hang forever waiting for a thread to be freed (which will never happen, since the running tasks CANNOT complete as they are blocked) Avoid this by releasing and reserving the current thread from the QgsPointCloudStatsCalculationTask before performing the blockingMapped function. --- src/core/pointcloud/qgspointcloudstatscalculator.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/pointcloud/qgspointcloudstatscalculator.cpp b/src/core/pointcloud/qgspointcloudstatscalculator.cpp index 5cefa09d7346..5d7955ddf417 100644 --- a/src/core/pointcloud/qgspointcloudstatscalculator.cpp +++ b/src/core/pointcloud/qgspointcloudstatscalculator.cpp @@ -209,7 +209,9 @@ bool QgsPointCloudStatsCalculator::calculateStats( QgsFeedback *feedback, const feedback->setProgress( 0 ); + QThreadPool::globalInstance()->releaseThread(); QVector list = QtConcurrent::blockingMapped( nodes, StatsProcessor( mIndex.get(), mRequest, feedback, 100.0 / ( double )nodes.size() ) ); + QThreadPool::globalInstance()->reserveThread(); for ( QgsPointCloudStatistics &s : list ) {