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

QThread::usleep on Windows should be removed or reimplemented

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P4: Low
    • 5.12.1
    • 5.4.2, 5.12.0 Alpha
    • Documentation
    • None
    • Windows
    • aa18467442011a8ad26ca6396c2bb44f44aba569 (qt/qtbase/5.12)

    Description

      On Windows, QThread::usleep is implemented like this:

      https://github.com/qt/qtbase/blob/5.11/src/corelib/thread/qthread_win.cpp#L464

      i.e. it lies to you and actually calls a Sleep which is millisecond precise.

      This is bad thing because this makes the user thinks QThread:usleep is microsecond accurate, and it's not.

      I know sleep functions are not reliable by nature, but here Qt is intentionally loosing precision on the number passed to the QThread::usleep function.

      Removing the function from Qt for Windows would make clear that QThread's sleep can't be microsecond precise on Windows.

      This will not be source compatible, and cause issues when porting Qt code from Unix to Windows, but IMO letting some Unix migrated code calling QThread::usleep on Windows silently compiles without any error is misleading, because it hides potential issues on the loose of precision.

      At least a message on the documentation would be nice.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            arnaud.bienner Arnaud Bienner
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes