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

QtConcurrentRun calls non-qt function



  • Hi,

    When QtConcurrentRun calls a non-qt function (c++ oop library), it has a chance to crash.
    Tested multiple times under exactly same conditions.

    Is this a known problem?
    Or it is simply my non-qt function has bug?

    Thanks.


  • Lifetime Qt Champion

    Hi,

    QtConcurrentRun doesn't need your function to be Qt specific. Can you share the code of that function ?



  • [quote author="SGaist" date="1424711613"]Hi,

    QtConcurrentRun doesn't need your function to be Qt specific. Can you share the code of that function ?[/quote]

    Here is QtConcurrentRun function.
    _brc is an object in non-qt library.
    Usually crash(show disassembler view) after line 5.

    @void Spectrometer::doScanning()
    {
    if(_isFunctional==false) return; // disable operation if not functional

    int result = _brc->startAcquiring();
    
    //emit dataAcquisitionFinished(); // tell manager this data has been acquired.
    
    quint16 dataBuffer[SpectrometerData::PIXEL_NUM];
    if(result == 1){
        result = _brc->getYData(dataBuffer);
    }
    else{
        // TODO:add error message box
        return;
    }
    
    _data_ptr.data()->updateUid(); // make new id to avoid duplication.
    
    //for flipped Spectrometer
    for(int i=0;i<SpectrometerData::PIXEL_NUM;i++){
        auto y = dataBuffer[SpectrometerData::PIXEL_NUM-i-1];
        _data_ptr.data()->updateY(i,y);
    }
    
    _isWorking=false;
    qDebug() << "Scan Finished";
    emit scanFinished();
    

    }@

    @bool BRC::startAcquiring(){
    char cmd[]="E\r\n";
    int cmdLength = strlen(cmd);
    if (write(_fd, cmd, cmdLength) < cmdLength){
    return false;
    }
    return (wait("DR",cmdLength+7, _timeout));
    }@


  • Lifetime Qt Champion

    You are trying to write on the same file descriptor from several thread at once ?



  • [quote author="SGaist" date="1424727828"]You are trying to write on the same file descriptor from several thread at once ?[/quote]

    No, BRC is a class, and each BRC object has its own file descriptor.


  • Lifetime Qt Champion

    Can you also show your call to QtConcurrentRun ?



  • Device manager contains two spectrometers,

    @bool DeviceManager::scan()
    {
    _meter0->scan(); // scan in parallel
    _meter1->scan(); // scan in parallel
    return true;
    }@
    @bool Spectrometer::scan()
    {
    _progress = 0;
    emit reportProgress(_progress);
    // this will run parallel
    QtConcurrent::run(this,&Spectrometer::doScanning);
    _isWorking=true;
    return true;
    }@


  • Lifetime Qt Champion

    Then are you sure that _brc is properly allocated ? That both are no trying to access the same resources at the same time ?



  • _brc is a pointer in Spectrometer class.
    and I use new BRC() in Spectrometer's constructor.
    Works most of time.

    and during my app starts up, each _brc did communicate with their corresponding hardware successfully.

    Is it possible to allocate differently with same code but different runs?


  • Lifetime Qt Champion

    What does the backtrace of a crash tell you ?



  • you mean stack trace?

    two lines of ??

    [quote author="SGaist" date="1424896978"]What does the backtrace of a crash tell you ?[/quote]


  • Lifetime Qt Champion

    Are you running a debug build ?



  • [quote author="SGaist" date="1424993803"]Are you running a debug build ?
    [/quote]

    Yes


  • Lifetime Qt Champion

    Ok, then what does the debugger tell you ?


Log in to reply