Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-100405

Data race on QCoreApplication

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.0 RC2
    • Fix Version/s: None
    • Labels:
      None

      Description

      I found this Thread Sanitizer stack. It happens from time to time.

       

      ==================                                                                                                                                                                                                 
      WARNING: ThreadSanitizer: data race (pid=147125)                                                                        
        Read of size 8 at 0x7b1400012840 by thread T1 (mutexes: write M59250034950757320):                                    
          #0 QXcbEventQueue::wakeUpDispatcher() /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbeventqueue.cpp:254 (libQt5XcbQpa.so.5+0x8ac49)
          #1 QXcbEventQueue::run() /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbeventqueue.cpp:236 (libQt5XcbQpa.so.5+0x8ae25)
          #2 QThreadPrivate::start(void*) /inout/qt5/qtbase/src/corelib/thread/qthread_unix.cpp:329 (libQt5Core.so.5+0x1008d4)
                                                                                                                                 
        Previous write of size 8 at 0x7b1400012840 by main thread:                                                               
          #0 QAbstractEventDispatcher::QAbstractEventDispatcher(QAbstractEventDispatcherPrivate&, QObject*) /inout/qt5/qtbase/src/corelib/kernel/qabstracteventdispatcher.cpp:160 (libQt5Core.so.5+0x3fa4c0)
          #1 QEventDispatcherGlib::QEventDispatcherGlib(QEventDispatcherGlibPrivate&, QObject*) /inout/qt5/qtbase/src/corelib/kernel/qeventdispatcher_glib.cpp:609 (libQt5Core.so.5+0x49698c)
          #2 QXcbGlibEventDispatcher::QXcbGlibEventDispatcher(QXcbConnection*, QObject*) /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp:110 (libQt5XcbQpa.so.5+0x8cd75)
          #3 QXcbEventDispatcher::createEventDispatcher(QXcbConnection*) /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp:153 (libQt5XcbQpa.so.5+0x8d0fd)
          #4 QXcbIntegration::createEventDispatcher() const /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbintegration.cpp:343 (libQt5XcbQpa.so.5+0x46541)
          #5 QGuiApplicationPrivate::createEventDispatcher() /inout/qt5/qtbase/src/gui/kernel/qguiapplication.cpp:1503 (libQt5Gui.so.5+0x1346da)
          #6 QApplicationPrivate::createEventDispatcher() /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:167 (libQt5Widgets.so.5+0x174d4d)
          #7 QCoreApplicationPrivate::init() /inout/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp:834 (libQt5Core.so.5+0x40b81d)
          #8 QGuiApplicationPrivate::init() /inout/qt5/qtbase/src/gui/kernel/qguiapplication.cpp:1527 (libQt5Gui.so.5+0x1390be)
          #9 QApplicationPrivate::init() /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:513 (libQt5Widgets.so.5+0x1770c0)
          #10 QApplication::QApplication(int&, char**, int) /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:501 (libQt5Widgets.so.5+0x1771ec)
          #11 main /home/breno/workspace/qtbug/qtbug2/main.cpp:7 (main+0x40140e)                                                 
      
        Location is heap block of size 80 at 0x7b1400012840 allocated by main thread:                                            
          #0 operator new(unsigned long) /tmp/gcc-v9.3.0/gcc.source/libsanitizer/tsan/tsan_new_delete.cc:63 (libtsan.so.0+0x731fa)
          #1 QXcbEventDispatcher::createEventDispatcher(QXcbConnection*) /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp:153 (libQt5XcbQpa.so.5+0x8d0ed)
          #2 QXcbIntegration::createEventDispatcher() const /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbintegration.cpp:343 (libQt5XcbQpa.so.5+0x46541)
          #3 QGuiApplicationPrivate::createEventDispatcher() /inout/qt5/qtbase/src/gui/kernel/qguiapplication.cpp:1503 (libQt5Gui.so.5+0x1346da)
          #4 QApplicationPrivate::createEventDispatcher() /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:167 (libQt5Widgets.so.5+0x174d4d)
          #5 QCoreApplicationPrivate::init() /inout/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp:834 (libQt5Core.so.5+0x40b81d)
          #6 QGuiApplicationPrivate::init() /inout/qt5/qtbase/src/gui/kernel/qguiapplication.cpp:1527 (libQt5Gui.so.5+0x1390be)
          #7 QApplicationPrivate::init() /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:513 (libQt5Widgets.so.5+0x1770c0)
          #8 QApplication::QApplication(int&, char**, int) /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:501 (libQt5Widgets.so.5+0x1771ec)
          #9 main /home/breno/workspace/qtbug/qtbug2/main.cpp:7 (main+0x40140e)
      
        Location is heap block of size 80 at 0x7b1400012840 allocated by main thread:                                            
          #0 operator new(unsigned long) /tmp/gcc-v9.3.0/gcc.source/libsanitizer/tsan/tsan_new_delete.cc:63 (libtsan.so.0+0x731fa)
          #1 QXcbEventDispatcher::createEventDispatcher(QXcbConnection*) /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbeventdispatcher.cpp:153 (libQt5XcbQpa.so.5+0x8d0ed)
          #2 QXcbIntegration::createEventDispatcher() const /inout/qt5/qtbase/src/plugins/platforms/xcb/qxcbintegration.cpp:343 (libQt5XcbQpa.so.5+0x46541)
          #3 QGuiApplicationPrivate::createEventDispatcher() /inout/qt5/qtbase/src/gui/kernel/qguiapplication.cpp:1503 (libQt5Gui.so.5+0x1346da)
          #4 QApplicationPrivate::createEventDispatcher() /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:167 (libQt5Widgets.so.5+0x174d4d)
          #5 QCoreApplicationPrivate::init() /inout/qt5/qtbase/src/corelib/kernel/qcoreapplication.cpp:834 (libQt5Core.so.5+0x40b81d)
          #6 QGuiApplicationPrivate::init() /inout/qt5/qtbase/src/gui/kernel/qguiapplication.cpp:1527 (libQt5Gui.so.5+0x1390be)
          #7 QApplicationPrivate::init() /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:513 (libQt5Widgets.so.5+0x1770c0)
          #8 QApplication::QApplication(int&, char**, int) /inout/qt5/qtbase/src/widgets/kernel/qapplication.cpp:501 (libQt5Widgets.so.5+0x1771ec)
          #9 main /home/breno/workspace/qtbug/qtbug2/main.cpp:7 (main+0x40140e)  

      I may be missing some mutex (that maybe TSan missed too) but this seems to be the relevant code:

      void QGuiApplicationPrivate::createEventDispatcher()                                                                    
      {                                                                                                                       
          Q_ASSERT(!eventDispatcher);                                                                                         
                                                                                                                              
          if (platform_integration == nullptr)                                                                                
              createPlatformIntegration();                                                                                    
                                                                                                                              
          // The platform integration should not mess with the event dispatcher                                               
          Q_ASSERT(!eventDispatcher);                                                                                         
                                                                                                                              
          eventDispatcher = platform_integration->createEventDispatcher();                                                                                                                                               
      }  

       

      In this case, the call to "createPlatformIntegration()" eventually creates the "QXcbEventQueue" thread.

      After that, this method goes to create and initialize the event dispatcher.

      However, the QXcbEventQueue also wants to know if the event dispatcher is there:

      void QXcbEventQueue::wakeUpDispatcher()                                                                                 
      {                                                                                                                       
          QMutexLocker locker(&qAppExiting);                                                                                  
          if (!dispatcherOwnerDestructing) {                                                                                                                                                                             
              // This thread can run before a dispatcher has been created,                                                    
              // so check if it is ready.                                                                                     
              if (QCoreApplication::eventDispatcher())                                                                        
                  QCoreApplication::eventDispatcher()->wakeUp();                                                              
          }                                                                                                                   
      }

      There we have the race on "eventDispatcher" since it seems to be static and non-atomic.

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            thiago Thiago Macieira
            Reporter:
            breno_guimaraes Breno Rodrigues Guimarães
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes