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

Problems with Qml+QtConcurrency on imx.6



  • Hello.
    I've noted the different behavior of the same application on different platforms: x86_64 and ARM (imx6).

    I tried to call some parallel logic from event handler of QML.

    On x86_64 all works fine and clear.
    But on ARM QtConcurrency doesn't fire the body of function, BUT in the same time isStarted() and isRunning() both return 'true'.

    For example:
    main.qml

    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        Component.onCompleted: NMgr.callOnAppWindowCompleted()
        onClosing: NMgr.callOnAppWindowClosed()
    
        Shortcut { sequence: "Ctrl+q"; onActivated: NMgr.callOnUserEvent() }
    }
    

    appnative.h

    class AppNative: public QObject
    {
        bool pflg = false;
        QFuture<void> plf;
        QFuture<void> pmf;
        QFuture<void> puf;
    
        QTimer* tlf;
        QTimer* tmf;
    
    Q_OBJECT public:
    
        explicit AppNative();
        virtual ~AppNative();
    
        Q_INVOKABLE void callOnAppWindowCompleted();
        Q_INVOKABLE void callOnAppWindowClosed();
        Q_INVOKABLE void callOnUserEvent();
    
    private:
    
        void parallelMemberFunc();
        void timerMemberFunc();
    };
    

    appnative.cpp

    AppNative::AppNative()
    {
        tlf = new QTimer(this);
        tmf = new QTimer(this);
    
        auto timerLambdaFunc = [&]() {
            qDebug() << "      1000: Hello from timer lambda function!";
        };
    
        connect(tlf, &QTimer::timeout, this, timerLambdaFunc);
        connect(tmf, &QTimer::timeout, this, &AppNative::timerMemberFunc);
    }
    
    AppNative::~AppNative()
    {
        plf.~QFuture();
        pmf.~QFuture();
    
        tlf->~QTimer();
        tmf->~QTimer();
    }
    
    void AppNative::parallelMemberFunc()
    {
        while (pflg) {
            qDebug() << "   500: Hello from parallel member function!";
            QThread::msleep(500);
        }
    }
    
    void AppNative::timerMemberFunc()
    {
        qDebug() << "         2000: Hello from timer member function!";
    }
    
    void AppNative::callOnAppWindowCompleted()
    {
        auto parallelLambdaFunc = [&]() {
            while (pflg) {
                qDebug() << "250: Hello from parallel lambda function!";
                QThread::msleep(250);
            }
        };
    
        pflg = true;
        plf  = QtConcurrent::run(parallelLambdaFunc);
        pmf  = QtConcurrent::run(this, &AppNative::parallelMemberFunc);
    
        tlf->start(1000);
        tmf->start(2000);
    }
    
    void AppNative::callOnAppWindowClosed()
    {
        pflg = false;
        plf.waitForFinished();
        pmf.waitForFinished();
    
        tlf->stop();
        tmf->stop();
    }
    
    void AppNative::callOnUserEvent()
    {
        qDebug() << "Try to run parallel event handler...";
        puf = QtConcurrent::run([] { qDebug() << "--> Hello from parallel event handler..."; });
    }
    

    x86_64 output:

    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
             2000: Hello from timer member function!
          1000: Hello from timer lambda function!
       500: Hello from parallel member function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
       500: Hello from parallel member function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    --> Hello from parallel event handler...
    ...
    

    ARM:

    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
          1000: Hello from timer lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
          1000: Hello from timer lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
             2000: Hello from timer member function!
          1000: Hello from timer lambda function!
    250: Hello from parallel lambda function!
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
          1000: Hello from timer lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    Try to run parallel event handler...
    250: Hello from parallel lambda function!
    ...
    ...
    

    There were missed calls of parallel method with message"500:..." and parallel handler of user's event (hotkey Ctrl+q).
    In more complex application the same problem rise more often.

    Could anybody clarify, what I'm doing wrong?
    Why there is different behavior of the same application on different platforms?

    I can share full project of this simple test application.

    Thanks!



  • @r3d9u11 seems like related to resources limitations.
    if try to change QThreadPool::globalInstance()->setMaxThreadCount and set needed thread count, all work fine.



  • @r3d9u11 seems like related to resources limitations.
    if try to change QThreadPool::globalInstance()->setMaxThreadCount and set needed thread count, all work fine.


Log in to reply