Page 1 of 1

Clock_nanosleep issues

Posted: Wed Jul 03, 2019 3:48 pm
by longo92
Hi,
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);
       }
After some time all threads are blocked in the clock_nanosleep function without waking up endlessly.
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?

Re: Clock_nanosleep issues

Posted: Wed Jul 03, 2019 4:42 pm
by joan
Could you post a complete program which shows the problem? One which we can run and test.

Re: Clock_nanosleep issues

Posted: Thu Aug 08, 2019 7:10 am
by longo92
Sorry but the program is too compex (streaming video and audio app), the problem is that the timer doesn't trigger interrupts at some point in time (check /proc/interrupts), so my processes waiting in nanosleep cannot awake.

Re: Clock_nanosleep issues

Posted: Thu Aug 08, 2019 8:43 am
by joan
We don't need your existing code. We need the smallest program you can create which exhibits the problem. Additionally the act of preparing such a program may point you to a bug in your code.

Re: Clock_nanosleep issues

Posted: Thu Aug 08, 2019 8:01 pm
by knute
joan wrote:
Thu Aug 08, 2019 8:43 am
We don't need your existing code. We need the smallest program you can create which exhibits the problem. Additionally the act of preparing such a program may point you to a bug in your code.
From the wayback machine a SSCCE. http://www.sscce.org/

Thank you Andrew Thompson.