Restart Xenomai Thread if Exceed the Time

23 views Asked by At

I'm developing a real-time C++ application on Ubuntu using Xenomai. I have a main process that is hard real-time, where I create a secondary thread that is not hard real-time. In this non real-time thread, I have a loop where I execute some instructions. I would like to stop the execution of the loop and restart it, also delete and restart the thread is fine but it is better to restart the loop, as soon as it exceeds a specified time, without waiting for the end of the loop. Is there any mechanism to do that, for example using interrupts or something from the Xenomai API?

Im using rt_task_spawn() to start the thread and rt_task_set_periodic() to set the thread period. The function executed by the thread looks like

void RTClass::functionThread()
{

    rt_task_set_periodic(&thread_ , TM_NOW, PERIOD_THREAD_TICKS);

    while(is_thread_running_)
    {

        function1();

        function2();

        function3();
        
        rt_task_wait_period(nullptr);

    }
}

Once started, the thread executes this while loop. I would like to restart this loop if it is unable to finish executing all instructions within the loop in PERIOD_THREAD_TICKS time. I can put a check after every single instruction, but this is not very nice.

Is it possible? There exists some Xenomai function to handle this?

0

There are 0 answers