I’m developing an application that needs to send out messages at specific times (it’s to do with multimedia so the timing precision is important), so effectively I need a mechanism to call a callback function in a specified number of milliseconds.
I need to support both Windows and Mac OS X. I’ve looked into Timer Queues on Windows which looks like what I need, but I have read that the timing precision is just not precise enough for multimedia based applications (my application is sensing MIDI messages to a driver at specific times). Any ideas?
I think your best bet on Windows is to use Multimedia Timers. On OS X, the simplest function to use would be
nanosleep, but you can go a long way with kqueue. I don’t think there will be any problems if you are talking milliseconds precision (a millisecond is a very, very long time). The only thing you will possibly need to do is to make sure OS runs your process as “real-time”.