QThread isRunning always true

154 views Asked by At

I am using QT 5.11.2 on both linux and windows. I am trying to optimize my UI to prevent it from freezing in large functions. I started using QThread and was able to do exactly what I want on windows. However, I tried to test the same functions on linux RHEL7 but threads never finished.

Here is what I tried:

void MainWidget::Configure_BERT_DSO(bool isOptimization, double lineRate, int Scaling)
{
    QThread *bertThread = QThread::create([this, lineRate, Scaling]{ ConfigureBert(lineRate, Scaling); 

    QThread *dsoThread = QThread::create([this, lineRate]{ ConfigureDSO(lineRate); });

    bertThread->setObjectName("My Bert Thread");
    dsoThread->setObjectName("My DSO Thread");

    bertThread->start();
    dsoThread->start();

    while(bertThread->isRunning() || dsoThread->isRunning())  //  even tried isFinished()
    {
        qApp->processEvents();
    }

    bertThread->exit();
    dsoThread->exit();

    delete bertThread;
    delete dsoThread;
}

In windows the while loop exits after a while and both threads execute correctly with no problem. On linux, to make sure that both functions execute correctly, I added qDebug() at the start and end of each function and they are all reached at the excpected time. But the problem is that isRunning never becomes true again and the same goes for isFinished and my loop gets stuck.

Thread: QThread(0x1d368b0, name = "My Bert Thread") started.

Thread: QThread(0x1d368e0, name = "My DSO Thread") started.

Thread: QThread(0x1d368b0, name = "My Bert Thread") finished.

Thread: QThread(0x1d368e0, name = "My DSO Thread") finished.

Is it something platform dependent or is there something that I might be missing?

EDIT I also tried to use bertThread->wait() and dsoThread->wait() to check if it exits after my functions finish but it never returns from the first one I called although both functions reach their end successfully

Your help is much appreciated

0

There are 0 answers