Note that there are some explanatory texts on larger screens.

plurals
  1. POWaitable timer spotty precision
    primarykey
    data
    text
    <p>I'm using a version of the following code in my actual production code. It sets a waitable timer for some time in the future and then has one worker thread waiting for it to fire:</p> <pre><code>//Create timer hWTimer = ::CreateWaitableTimer(NULL, FALSE, NULL); //Number of minutes to wait int nMinutesToWait = 5; //Predict when it should fire COleDateTime dtWhen = COleDateTime::GetCurrentTime() + COleDateTimeSpan(0, 0, nMinutesToWait, 0); //Set timer SetWaitableTimerSecondsFromNow(hWTimer, nMinutesToWait * 60); //Waiting part if(::WaitForSingleObject(hWTimer, INFINITE) == WAIT_OBJECT_0) { //Timer has fired, compare when _TRACE(L"Time scheduled for: %s, time fired: %s", dtWhen.Format(), COleDateTime::GetCurrentTime().Format()); } BOOL SetWaitableTimerSecondsFromNow(HANDLE hWTimer, double fSecs2Wait) { //INFO: I'm setting the timer to a relative time to ensure that it // doesn't fire in case the system clock is adjusted. LARGE_INTEGER li; li.QuadPart = -10000000LL * (LONGLONG)fSecs2Wait; //Convert to 100 nanosecond intervals (MUST BE NEGATIVE) if(li.QuadPart &gt;= 0) return FALSE; return ::SetWaitableTimer(hWTimer, &amp;li, 0, NULL, NULL, FALSE); } </code></pre> <p>It works well and in most circumstances the time when the timer needs to fire and when it actually fires is a 100% match. But very rarely, the timer fires 10-15 seconds earlier for just a 5 minute wait. It also seems like this issue mostly happens on Windows XP.</p> <p>Does anyone have any idea what's going on here and how to mitigate it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload