i have a multi-threaded program with a certain number of periodic threads.
The typical periodic thread code is the following:
Code: Select all
static void time_add_ms(struct timespec *t, int ms)
{
t->tv_sec += ms/1000;
t->tv_nsec += (ms%1000)*1000000;
if (t->tv_nsec > 1000000000) {
t->tv_nsec -= 1000000000;
t->tv_sec += 1;
}
}
void* tread()
{
struct timespec t;
int period = THREAD_PERIOD; //PERIOD IN MILLISECONDS
int counter = 0;
clock_gettime(CLOCK_MONOTONIC,&t);
time_add_ms(&t,period);
while(1)
{
/* DO SOMETHING*/
clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,t,NULL);
time_add_ms(t,period);
}
If i launch every terminal commands (top, ping, etc...)that contain a sleep function they are blocked on sleep function itself.
Does someone register the same issue?