Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem for While(true) in QT QThread Run function



  • Hi,

    All,

    I created one thread, and the run function looks like below:

    void Compass_Message_Handler::run()
    {
        this->handleMessage();
    
        return;
    }
    
    void Compass_Message_Handler::handleMessage()
    {
        while(true)
        {
            if(m_canHandleNxtMsg)//line A
            {
                ////////////////////////////////////
    /////////////////////////////////////////////////
            }
        }
    }
    

    I set a break point at line A. but i find that after several execution, i need to wait for 3 to 5 seconds for the while to run again to the break point line A.

    Do you know why, is it because multi thread and the cpu need to run other thread??????

    [Fixed code formatting ~kshegunov]


  • Qt Champions 2017

    welcome to the forum. I don't see any issue with your code. Do you see the same behaviour when you run the above program without break point ? What are you doing inside the if condition ?



  • Hi,

    Dheerendra,

    Thanks for your answer, i still not check if i run not in debug mode.

    I will check it ,thanks.


  • Lifetime Qt Champion

    @dheerendra Asked what you are doing inside that if() condition. Is it something long lasting?


Log in to reply