Is there a function that allow to execute a task only for a limited number of ticks?

Hi, i should know if there’s a function that can execute a task within a range of limited ticks (effective, excluding preemption from higher priority task), after which it automatically suspend or send an interrupt.

There is no function that a task can call to do that. All it can do is block itself by calling a function that is waiting for an event (like a task notification). Alternatively a timer interrupt could suspend it.

However, if you were to explain what you were trying to achieve we may be able to suggest an alternative.

One thing that is close, if the Timer task is given a high priority, would be to start a timer which in the timer call back suspends the task. This gives a limited maximum clock time and doesn’t adjust for time spent in higher priority tasks. If the task finishes in time, it can cancel or restart the timer.

The one big problem is that if the task is holding any resources when it is suspended, it will continue to hold them, so that can well be a problem. Maybe better would be to drop its priority to let anything else you were wanting to get a chance to be able to run.

As Richard Barry asked, knowing what you are trying to do might help us to help you. As a comment, it is better to try to write your tasks to be correct, rather than try to get something to enforce them to be less bad in case of problems tends to be the better tact.