Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtConcurrent::map cause crash
Forum Updated to NodeBB v4.3 + New Features

QtConcurrent::map cause crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • TonyTangT Offline
    TonyTangT Offline
    TonyTang
    wrote on last edited by Christian Ehrlicher
    #1

    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();
    
    JonBJ 1 Reply Last reply
    0
    • TonyTangT TonyTang

      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();
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      TonyTangT 1 Reply Last reply
      0
      • JonBJ JonB

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

        TonyTangT Offline
        TonyTangT Offline
        TonyTang
        wrote on last edited by
        #3

        @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() 未知

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Your code works fine here.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          TonyTangT 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Your code works fine here.

            TonyTangT Offline
            TonyTangT Offline
            TonyTang
            wrote on last edited by
            #5

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

            Christian EhrlicherC 1 Reply Last reply
            0
            • TonyTangT TonyTang

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

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              TonyTangT 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @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.

                TonyTangT Offline
                TonyTangT Offline
                TonyTang
                wrote on last edited by
                #7

                @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() 未知

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved