Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions
[Solved]Can't run multiple thread on Linux
antonyprojr last edited by
I'm trying to develop a program that run two thread for testing in Windows and Linux.
One thread is locked by mutex and another thread increase +10 to int i.
In Windows i get 10,20,30... , but in linux it always display 0.
Apparently the thread are connected, and the second thread never can increase +10 to i.
What is wrong with my code?
i += 10;
if (!t1.isRunning()) t1 = QtConcurrent::run(this, &MainWindow::thread1);
if (!t2.isRunning()) t2 = QtConcurrent::run(this, &MainWindow::thread2);
QMessageBox *msgbox = new QMessageBox(this);
alexisdm last edited by
If there is only one available thread in the thread pool, it won't execute the thread2 function.
Maybe Qt didn't detect the number of cores/threads of your CPU (I assume it has more than 1 if it works on Windows). That number is returned by QThread::idealThreadCount, which, on linux, uses sysconf(_SC_NPROCESSORS_ONLN), which itself only returns the number of online processors as the name implies (I don't know if power saving affects the number returned by that function).
Anyway, you can force a fixed number of threads with: