Skip to content

Commit 8e6bc17

Browse files
committedMar 3, 2023
Don't allow users to set maximum thread count for rendering to 1
(This setting can sometimes unwantedly occur when using the same profile across sessions of newer to very old QGIS versions) The option is a misleading, as it's actually setting the global thread limit for the entire QGIS application. If we allow this to be set to a limit of 1 thread, then deadlocks occur from the QImage internals in unpredictable ways.
1 parent eecfd4a commit 8e6bc17

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed
 

‎python/core/auto_generated/qgsapplication.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ Set maximum concurrent thread count
680680

681681
.. note::
682682

683-
must be between 1 and \#cores, -1 means use all available cores
683+
must be between 2 and \#cores, -1 means use all available cores
684684

685685
.. versionadded:: 2.4
686686
%End

‎src/app/options/qgsrenderingoptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ QgsRenderingOptionsWidget::QgsRenderingOptionsWidget( QWidget *parent )
3232
QgsSettings settings;
3333
chkAddedVisibility->setChecked( settings.value( QStringLiteral( "/qgis/new_layers_visible" ), true ).toBool() );
3434

35-
spinMaxThreads->setRange( 0, QThread::idealThreadCount() );
36-
spinMaxThreads->setClearValue( 0, tr( "All Available (%1)" ).arg( QThread::idealThreadCount() ) );
35+
spinMaxThreads->setRange( 1, QThread::idealThreadCount() );
36+
spinMaxThreads->setClearValue( 1, tr( "All Available (%1)" ).arg( QThread::idealThreadCount() ) );
3737
if ( QgsApplication::maxThreads() != -1 )
3838
spinMaxThreads->setValue( QgsApplication::maxThreads() );
3939
else

‎src/core/qgsapplication.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,10 +2313,13 @@ void QgsApplication::setMaxThreads( int maxThreads )
23132313
QgsDebugMsgLevel( QStringLiteral( "maxThreads: %1" ).arg( maxThreads ), 2 );
23142314

23152315
// make sure value is between 1 and #cores, if not set to -1 (use #cores)
2316-
// 0 could be used to disable any parallel processing
23172316
if ( maxThreads < 1 || maxThreads > QThread::idealThreadCount() )
23182317
maxThreads = -1;
23192318

2319+
// force at least 2 threads -- anything less risks deadlocks within Qt itself (e.g in QImage internal mutexes)
2320+
if ( maxThreads > 0 && maxThreads < 2 )
2321+
maxThreads = 2;
2322+
23202323
// save value
23212324
ABISYM( sMaxThreads ) = maxThreads;
23222325

‎src/core/qgsapplication.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ class CORE_EXPORT QgsApplication : public QApplication
656656

657657
/**
658658
* Set maximum concurrent thread count
659-
* \note must be between 1 and \#cores, -1 means use all available cores
659+
* \note must be between 2 and \#cores, -1 means use all available cores
660660
* \since QGIS 2.4
661661
*/
662662
static void setMaxThreads( int maxThreads );

0 commit comments

Comments
 (0)
Please sign in to comment.