0

We are trying to create a timer that fires every 14 ms or so with a maximum tolerable inaccuracy of ~2ms.

We tried timer queue timers, waitable timers and threadpool timers and even though most work really well on my AMD processor (with the most accurate being threadpool timers with high priority), when we try to test the timers with Intel processors, we hit the 15ms roadblock where the timer only works within 15 ms increments.

We found that the timeBeginPeriod function in the Windows Multimedia API provides us with a way of changing the resolution, however the documentation states that the multimedia timers are obsolete and we should work with timer queue timers (which were then replaced by threadpool timers). Even when we somehow call the timeBeginPeriod function, we can not change the resolution to anything other than 15ms.

We read a lot about certain applications (like Chrome) changing the resolution of the timers and it being bad practice due to increased power consumption. We even had a test where our Intel processor magically had a small enough timer resolution probably because of another process in the background tampering with the timer resolution. But we could not reproduce the test ever since.

How can we change the resolution from 15ms effectively, or is there another way of creating millisecond accurate timers other than threadpool timers or timer queue timers (without leaving a thread to count nanoseconds indefinitely)?

  • 3
    Windows is simply not a real-time OS, you are not likely to *reliably* get the kind of resolution you are asking for from system timers/queues. Consider alternative approaches. – Remy Lebeau Feb 09 '22 at 17:26
  • The best you can do is to override the Interrupt Service Routine to call your function, then call the OS function. Think of the Windows timers as "at least this time, maybe more". – Thomas Matthews Feb 09 '22 at 17:49
  • Can you change your design from Time-Based to Event Driven? Instead of doing an activity every 15ms, figure out what event is occurring and design the code to take advantage of the event. – Thomas Matthews Feb 09 '22 at 17:52

0 Answers0