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

QtConcurrent::map cause crash



  • dear all:
    when I call QtConcurrent::map,the program crashs down sometimes. I do not know why.thanks for your suggestion! my code as following :

    void MutiFun(int& i)
    {
    	i *= 2;
    }
    const int nSize = 10000000;
    QList<int> dataArray1;
    for (int i = 0; i < nSize; i++)
    {
    	dataArray1.push_back(i);
    }
    QFuture<void> f = QtConcurrent::map(dataArray1, MutiFun);
    f.waitForFinished();
    


  • @TonyTang
    What does the debugger reveal in the stack trace pane when it "crashs down sometimes"?



  • @JonB

    Qt5Cored.dll!QGenericAtomicOps<QAtomicOpsBySize<4> >::store<int,int>(int & _q_value, int newValue) 行 89 C++
    Qt5Cored.dll!QBasicAtomicInteger<int>::store(int newValue) 行 120 C++
    Qt5Cored.dll!QFreeList<QMutexPrivate,`anonymous namespace'::FreeListConstants>::release(int id) 行 270 C++
    Qt5Cored.dll!QMutexPrivate::release() 行 601 C++
    Qt5Cored.dll!QMutexPrivate::deref() 行 106 C++
    Qt5Cored.dll!QBasicMutex::lockInternal(int timeout) 行 496 C++
    Qt5Cored.dll!QBasicMutex::lockInternal() 行 416 C++
    Qt5Cored.dll!QMutex::lock() 行 225 C++
    Qt5Cored.dll!QMutexLocker::relock() 行 147 C++
    Qt5Cored.dll!QThreadPoolThread::run() 行 105 C++
    Qt5Cored.dll!QThreadPrivate::start(void * arg) 行 387 C++
    ucrtbased.dll!00007ff828c8a1bc() 未知
    ucrtbased.dll!00007ff828c89e13() 未知
    kernel32.dll!00007ff8667a37e4() 未知
    ntdll.dll!00007ff86713cb81() 未知


  • Lifetime Qt Champion

    Your code works fine here.



  • @Christian-Ehrlicher
    sometimes it works fine,but sometimes not
    It may be the problem of multithreading synchronization


  • Lifetime Qt Champion

    @TonyTang I doubt there is a problem in the Qt implementation of QtConcurrent::map() so I would guess your code does more than you've shown above. The code above runs fine standalone, with valgrind, with address sanitizer and thread sanitizer (at least no real problems seen here). Also let your program run 10k times without any crash.



  • @Christian-Ehrlicher
    The whole code as following

    #include <QtCore/QCoreApplication>
    #include <QtConcurrent/QtConcurrent>
    #include <QList>
    #include <QDebug>
    #include <QThread>
    #include <QTime>
    void MutiFun(int& i)
    {
    i *= 2;
    }

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    const int nSize = 10000000;
    QList<int> dataArray1;
    for (int i = 0; i < nSize; i++)
    {
    	dataArray1.push_back(i);
    }
    QFuture<void> f = QtConcurrent::map(dataArray1, MutiFun);
    f.waitForFinished();
    
    return a.exec();
    

    }

    and stack trace is here
    ntdll.dll!00007ff8671d4c2e() 未知
    ntdll.dll!00007ff86718d063() 未知
    ntdll.dll!00007ff86711bf55() 未知
    KernelBase.dll!00007ff863ae136a() 未知
    ucrtbased.dll!00007ff828b3deb1() 未知
    ucrtbased.dll!00007ff828b3d350() 未知
    ucrtbased.dll!00007ff828b3faf9() 未知
    ucrtbased.dll!00007ff828b4075e() 未知
    Qt5Cored.dll!QListData::realloc_grow(int growth) 行 156 C++
    Qt5Cored.dll!QListData::append(int n) 行 185 C++
    Qt5Cored.dll!QListData::append() 行 193 C++

    Qt5Cored.dll!QList<QThreadPoolThread * __ptr64>::append(QThreadPoolThread * const & t) 行 592 C++
    Qt5Cored.dll!QQueue<QThreadPoolThread * __ptr64>::enqueue(QThreadPoolThread * const & t) 行 53 C++
    Qt5Cored.dll!QThreadPoolThread::run() 行 125 C++
    Qt5Cored.dll!QThreadPrivate::start(void * arg) 行 387 C++
    ucrtbased.dll!00007ff828b6a1bc() 未知
    ucrtbased.dll!00007ff828b69e13() 未知
    kernel32.dll!00007ff8667a37e4() 未知
    ntdll.dll!00007ff86713cb81() 未知


  • Lifetime Qt Champion

    I can't reproduce it with gcc7 or 10 on linux or msvc2019 16.8.3 / 64bit with Qt5.15.


Log in to reply