Is the following code correct
Adding an event:
pushEvent(std::chrono::steady_clock::now() + dt, event_obj);
In event loop:
//...
auto now=std::chrono::steady_clock::now();
if(event.expireTime<=now)
{
event.fire();
}
//...
I am somewhat worried about wrap-around behavior, as I know of at least two bugs [1] and [2], that was introduced due to wrap-around in time counters. What I think of could happen:
-
The event fires early, since
std::chrono::steady_clock::now() + dt
will be a smaller thanstd::chrono::steady_clock::now()
-
The event fires late, since
std::chrono::steady_clock::now()
may have a wrap-around already.
Aucun commentaire:
Enregistrer un commentaire