1

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.

Jack Sabbath
  • 1,398
  • 2
  • 9
  • 12
  • 1
    Have you looked at the standard [steady_clock](http://www.cplusplus.com/reference/chrono/steady_clock/)? – NathanOliver Mar 25 '15 at 16:57
  • @NathanOliver: Yes, but it provides only time stamps and not periodic callbacks. The only chance I see to make an exact time with this is to perform busy waiting, which I would like to avoid. As I said - the Windows Multimedia Timer can do it without busy waiting. – Jack Sabbath Mar 25 '15 at 17:01
  • Boost ASIO's implementation is platform specific. On Windows it uses IOCP, on Linux `epoll()`. In either case, 1ms resolution should be easily achievable. This question, however, is off topic for SO. – Chad Mar 25 '15 at 17:04
  • Well [I made a simple timer event system in an old answer](http://stackoverflow.com/a/11866539/440558), yes it's busy-waiting, but you could put that in a thread to not hinder your main thread. – Some programmer dude Mar 25 '15 at 17:04
  • I'm working on a timer library right now; I'm currently only interested (and capable) to make it work on linux. For that OS I also could't find anything with the precision and performance that I was after. In the end I chose to use the POSIX timer_create and timer_settime to get timer interrupts by POSIX signal (also called Real Time signals since the extension to 1024 signals with queuing). – Carlo Wood Apr 01 '18 at 11:58

1 Answers1

0

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.

stefan
  • 3,681
  • 15
  • 25