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

Signals were being sent from the Qt library in the wrong order. Analysis showed that this problem was in the QObjectPrivate::setThreadData_helper method, used when QObjects sending the signals were passed to another thread.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 4.8.0
    • 4.7.3
    • Core: Event loop
    • Microsoft Windows. The sample application works with MinGW and VC++ compilers, run in QtCreator 2.2.
    • 2ff9617cd6093a758dddea5ce50d1efd6e98ded8

    Description

      The problem:

      Signals in our server application were being received in the application in the wrong order.

      The problem was traced to the to the signals actually being sent in the wrong order from Qt library (QCoreApplicationPrivate::sendPostedEvents).

      Further inspection of the code showed that the reason that the signals were being sent out of order was because the events that represent those signals were being added out of order to the list of events to post (QCoreApplication::postEvent).

      When inserting a new event to the post-event-list, the code was using a binary search method (qUpperBound) to determine where the event should be placed(the list is sorted by event priority), but the list happened to be unsorted and thus the binary search gave a bogus answer (and the event inserted in the wrong position) since being sorted is a prerequisite for binary search to succeed.

      Since the code in QCoreApplication::postEvent itself was correctly taking event sorting into account we started looking for other places that modified the list to make sure the sorting was also preserved.

      We found QObjectPrivate::setThreadData_helper the method responsible of moving events from one event list to another when a given QObject is moved from a thread to a different one. This method was appending events to the target list without taking into account the sorting by priority, resulting in a unsorted list.

      The Fix:

      We decided to modify QObjectPrivate::setThreadData_helper to take into account the priority when inserting events to the list (by using the same code QCoreApplication::postEvent uses). After this change both the original tournament model code and the simple tester class did not report signals being received in the wrong order.

      The Postscript:

      There is still one place in (QCoreApplicationPrivate::sendPostedEvents) where events are being added to the event list without taking priority into account, it is a edge case that we have not been able to reproduce. We are still working on creating a reproduceable case within the confines of a test application.

      Attachments

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

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            reworled Rebecca Worledge
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes