Currently clock_nanosleep with CLOCK_MONOTONIC_RAW on Debian Jessie returns EOPNOTSUPP.
How to get around the problem and compensate for possible NTP adjustments that might apply to CLOCK_MONOTONIC in a timer cycle?
Is clock_nanosleep itself a change in NTP settings? If adjustments occur during sleep, will the clock_nanosleep sleep longer than expected?
And should I even worry about the possible CLOCK_MONOTONIC NTP settings in my particular case? What would be the largest possible “time transition” applied by NTP to CLOCK_MONOTONIC, given that my code will work on the system without a real-time clock and may interrupt the Internet connection from time to time?
Long story. I use a simple loop to emulate the playback of audio files, and I need to maintain a constant playback position.
clock_nanosleep with the TIMER_ABSTIME flag seems to work fine, but I'm not sure if CLOCK_MONOTONIC is enough to avoid noticeable transitions in the playback position.
Here is the code I'm using:
clock_gettime(CLOCK_MONOTONIC, &deadline); // run until asked to stop while(!need_quit(stop_mutex_signal)) { // do stuff ... // add time ms to previous deadline deadline.tv_nsec += device->periodTime * NANOSECONDS_PER_MILLISEC; // normalize the time to account for the second boundary if(deadline.tv_nsec >= NANOSECONDS_PER_SEC) { deadline.tv_nsec -= NANOSECONDS_PER_SEC; deadline.tv_sec++; } if(clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline, NULL) != 0) { // something happened - error or exit signal, cannot continue return; } }
I'm curious why the CLOCK_MONOTONIC_RAW support in clock_nanosleep is not yet implemented? Does this mean that CLOCK_MONOTONIC is sufficient for most cases, even for audio / video synchronization?
c timer
Justamartin
source share