longo92
Posts: 44
Joined: Mon Sep 03, 2018 3:45 pm
Contact: Website Skype

Clock_nanosleep issues

Wed Jul 03, 2019 3:48 pm

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?

User avatar
joan
Posts: 14074
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Clock_nanosleep issues

Wed Jul 03, 2019 4:42 pm

Could you post a complete program which shows the problem? One which we can run and test.

longo92
Posts: 44
Joined: Mon Sep 03, 2018 3:45 pm
Contact: Website Skype

Re: Clock_nanosleep issues

Thu Aug 08, 2019 7:10 am

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.

User avatar
joan
Posts: 14074
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Clock_nanosleep issues

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.

knute
Posts: 445
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Clock_nanosleep issues

Thu Aug 08, 2019 8:01 pm

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.

Return to “C/C++”