[Qt-interest] Do QTimer Race Conditions Exist

Bradley T. Hughes bradley.hughes at nokia.com
Fri Feb 12 10:34:21 CET 2010


On 02/11/2010 09:09 PM, Will Rutherdale (rutherw) wrote:
> If I take it on faith that this new id is different from the previous
> few, then yes I am okay, because any pending timer event will contain a
> timer id that is not equal to the current timer id.  If however the id
> could come back with the same value on successive calls, then I could be
> in trouble.
>
> Any idea whether these id's are unique and where I can verify that?

Actually, the timer id allocation code will reuse timer ids as often as 
possible. BUT, you don't have to worry about getting an unwanted QTimer 
timeout() signal.

As mentioned before, QTimer is event driven, and when you call stop(), Qt 
drops all resources associated with the event source that generates the 
timer events (even if there happened to be a pending timer event in the 
queue when stop() was called, that event is dropped). Calling start() on the 
timer immediately after calling stop() will most likely result in the timer 
getting the exact same timer id, BUT since the event source has been removed 
and all pending events discarded, the QTimer will not get a phantom event.

-- 
Bradley T. Hughes (Nokia-D-Qt/Oslo), bradley.hughes at nokia.com
Sandakervn. 116, P.O. Box 4332 Nydalen, 0402 Oslo, Norway



More information about the Qt-interest-old mailing list