Cross platform C++ High Precision Event Timer implementation

1.7k views Asked by At

Coming from the Windows platform I usually used the Windows Multimedia Timer to produce periodic callbacks with a resolution of 1 ms +-1ms. So I could indeed produce 1000 quite equidistant callbacks per second. To achieve this accuracy without doing busy-waiting MS used the High Precision Event Timer, which directly accesses a hardware driver.

I was hoping to find something like a boost library or so that provides a cross platform implementation for these kind of high precision timers. But all I found is the Boost-ASIO timers. Since they don't talk about precision at all, I'd assume that they won't meet the requirement a high precision. A jitter of 10ms would be way to much.

So.. is there something like a cross platform implementation of a High Precision Event Timer? Or might Boost-ASIO already be precise enough? Maybe Boost internally uses the HPET and just didn't mention it anywhere.

1

There are 1 answers

0
stefan On

There is no implementation that guarantees 1ms resolution across the full universe (PC, xbox, android mobiles, ...) . All implementations have to rely on the OS to provide this resolution and the OS needs hardware support. Implementations usually provide fallbacks to lower resolution and so do the OSes on different HW.

Boost (and new C++ standard) provide a generic interface but cannot guarantee 1ms. They provide the best you can get on the specific platform. You can get information about resolution at runtime and refuse to run.