windows media timer vs time.h which one will be more reliable in real time system?
i am using sleep function in ansi-c that gives a resolution up-to milliseconds but not exactly i faced uncertain delays, people suggest me to use windows media timer,
i want to know the comparison between both is they enough 开发者_开发问答reliable to use in real time system or to use some thing else,
thanx in Advance.
I developed this function for Linux and MacOSX machines. I hope it may help you.
// t => mili seconds
void Wait(unsigned long t)
{
#if defined(_LINUX) || defined(__APPLE__)
time_t secs;
long milisecs,
nanosecs;
struct timespec waittime;
secs = t / 1000L;
milisecs = t - (secs * 1000L);
nanosecs = milisecs * 1000000L;
waittime.tv_sec = secs;
waittime.tv_nsec = nanosecs;
nanosleep(&waittime, NULL);
#else
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = t * 1000L;
select(0, NULL, NULL, NULL, &timeout);
#endif
}
The sleep function is not in the ANSI C standard; if you're talking about the sleep
function (with lowercase s), it's the POSIX function, which still has a resolution of 1 second. Instead, probably you're talking about the Windows API Sleep
function (uppercase S), which has 1 ms resolution, but that isn't intended to be used when high precision is needed.
If you are on Windows, the suggestion that has been given to you is correct, you should use multimedia timers, that are specifically designed for soft-realtime needs such as multimedia playback.
精彩评论