sleep/nanosleep/select/poll all only give you one guarantee. You will sleep at least for the length of the timeout, but there is no reasonable upper bound. i.e. with 100 CPU bound processes you might have to wait up to a full second.

What you probably want is to 'busy loop without hogging the CPU'. You can do this with sched_yield() and checking how long we were out with gettimeofday.


#include <sys/time.h>
#include <sched.h>
void busy_loop_until(struct timeval *when)
{
struct timeval now;
while(1) {
gettimeofday(&now, NULL);
if (timercmp(&now, when, >=) break;
sched_yield();
}
}

It will just burn some (unused) CPU cycles when nothing else is runnable.
_________________________
40GB - serial #40104051 gpsapp