@Dtynin Try to implement a preemptive scheduler that can interrupt lower-priority tasks to run higher-priority tasks. This scheduler Will ensure that the critical tasks are executed in a timely manner.
Then, apply a kernel that manages the tasks and their execution. Check these points out,I believe it will be helpful to your project.