On Tuesday, 30 May 2023 15:52:48 PDT Jaroslaw Kobus via Development wrote:
> I don't know QTimer's internals, so I can't comment on this. However, please
> refer to what the CI machine reports for:
> https://codereview.qt-project.org/c/qt-creator/qt-creator/+/480663/1

After trying myself, it turns out the problem is not QTimer or the event 
dispatcher, but the Windows API. The following test:
  https://codereview.qt-project.org/c/qt/qtbase/+/480705
passes on Linux (glib and native), macOS but fails on Windows, all of them 
Core and Gui.

The difference between those two groups is the use of QTimerEventList. Or, said 
differently, retaining the order is a feature of that class. This can be 
noticed in the Glib and Cocoa implementations, which have a single timer 
source for the underlying processing mechanism and the timeout for that source 
is calculated at every loop iteration to be the shortest timeout (the timer 
that will activate the soonest).

The Windows implementation, however, creates a Windows timer source per timer 
that is registered. It appears that Windows internally stores those sources in 
a hash or some other container with arbitrary order, producing things like:

FAIL!  : tst_QTimer::singleShotSequentialTimers(25,25,25,25,25,25,50) Compared 
values are not the same
   Actual   (result)  : "AFBCDEG"
   Expected (expected): "ABCDEFG"

The two most common patterns appear to be complete reversal (FEDCBA) and the 
last timer in a given value to come ahead ("AEBCD", "AFBCDE", etc).

> When the target thread is busy, I can't expect the exact accuracy for the
> elapsed timeouts, and therefore I don't know how to interpret the "wakes up
> exactly when you asked it to"?

This may also explain why you're seeing a timeout of 2 happening before 1, 
when I can't in my test. Every time there's a step in value, the order gets 
retained. That is, for the 1,1,1,2,2,2,2 case, letters D-G never appeared 
mixed with A-C; in the 25,25,25,25,25,25,50 case, letter G was always last.

But if the thread got blocked for enough time that further timers expired 
before any got handled, then I assume the Windows internals will keep 
activating them in arbitrary order.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering

Attachment: smime.p7s
Description: S/MIME cryptographic signature

-- 
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development

Reply via email to