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

Order of initialization is incorrect for QCoreApplicationPrivate::theMainThread

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.10.0
    • Core: Threads
    • None

    Description

      Static build, Qt 5.10, VS15.5.5, Win10.

      In user code I have a global variable:

      QTranslator myTranslator;

      It is initialized earlier than (corelib/kernel/qcoreapplication.cpp):

      QBasicAtomicPointer<QThread> QCoreApplicationPrivate::theMainThread = Q_BASIC_ATOMIC_INITIALIZER(0);

       

      So, inside of translator there's initialization of QCoreApplicationPrivate::theMainThread that is overwritten later with 0, so I see an assertion Q_ASSERT(theMainThread.load() != 0);

       

      A workaround (fix?) is simple for my code - remove global translator. But similar things probably can be encountered with other global qt vars in user code, so qt-side fix will be useful.

       

      An obvious solution for me is to put that theMainThread variable completely inside the static member function to prevent that incorrect init from CRT due to ordering issues.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            egorpugin Egor Pugin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes