How does a low priority task execute when a high priority task takes over CPU control?

How does a low priority task execute when a high priority task takes over CPU control? High priority task takes control of CPU from low priority task due to which task 2 is not able to complete its 100% work. Suppose Task 2 completed 70% of the task, then Task 1 takes controls the CPU from Task 2.

When next time Task 2 gets control of the CPU, will Task 2 finish its remaining 30% work or start its work from the beginning?

Tasks resume where they were interrupted.

1 Like

It wouldn’t make any sense if a preempted task would be restarted instead of resumed.

1 Like

If a task does continue at the exact point where it was interrupted, will the system perform well. Would not Repetition of instructions lead to loss of results.?

Yes, it would. But Richard never implied nor (I am certain) meant that instructions would be repeated. The scheduler will restore the PC register of a resumed task to what the register contained when the task was suspended - just as any other MCU register, so when the task gets to run it has exactly the same execution state as it had when it got suspended.

1 Like

What repetition of instructions? The task resumes at the very instruction it would have executed next, with the CPU register restored to exactly how they were when the task was switched out.

This is exactly like an ISR interrupt, which resumes the program it returns to, because it basically is.

2 Likes