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

QThread::currentThread () results in crash when used in a plug-in

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.12
    • Core: Threads
    • None
    • Windows

    Description

      Qt will be used in a plug-in (dll). The plug-in will be created and deleted on the main-thread of a host. But a functon of the plug-in will be called in a Non-Qt-Worker-Thread. In that call QThread::currentThread () will be used. All is fine. Finally the plug-in will be released (FreeLibrary) and the host will be closed. But after that, the application will crash.

      We found that the problematic part happens here ...

      // qthread_win.cpp
      DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID)
       ret = WaitForMultipleObjects(handlesCopy.count(), handlesCopy.constData(), false, INFINITE);

      ... it waits and will never get through that point. 

      The problem - it seems to be - is that the creation of qt_adopted_thread_watcher_function happens inside the Non-Qt-Thread. And the design expects that this Non-Qt-Thread will be finished before the plug-in will be removed. But that's not possible. The plug-in creation goes like this

      • Start Host
      • Start Non-Qt-Worker-Thread
      • Load Plug-In
      • Call Plug-In call from a Worker-Thread
      • Remove Plug-In
      • Stop Non-Qt-Worked-Thread
      • Close Host

      I've attached a example to get a picture of the problem. The example has a host and a plug-in. Just compile the lib and the app and run the app. Wait 5 seconds and you will see the crash. A screenshot of the crash is also attached.  

      Thank you very much for taking your time to look into it.

      Attachments

        1. qtbug_crash.png
          qtbug_crash.png
          134 kB
        2. qtbug.zip
          2 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            cnn Qt Core & Network
            michaspork Michael Spork
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes