On Monday, 29 May 2023 11:40:14 PDT Jaroslaw Kobus via Development wrote:
> Hi All,
> 
> when I start 2 single shot timers synchronously in a row, with exactly the
> same interval, from the same thread, can I rely on having their handlers
> called in the same order in which they were started?
> 
> I.e.:
> 
> QTimer::singleShot(1000, [] { qDebug() << "1st timer elapsed"; });
> QTimer::singleShot(1000, [] { qDebug() << "2nd timer elapsed"; });
> 
> Should I always see the:
> 
> 1st timer elapsed
> 2nd timer elapsed
> 
> on the output, or should I expect the random order?

Strictly speaking, no, you can't. Because timers aren't precise, timers can be 
delivered early or late by 5% if they are Coarse. Therefore, the order will 
depend on which direction the rounding went, which depends on how long it took 
you between scheduling those two timers.

It will depend on the timeout too. For single-shot timers, timers below 2 
seconds are Precise, which means only those above that threshold will suffer 
reordering.

For non-QTimer::singleShot, all timers are Coarse by default.
-- 
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