Brendan's Multi-tasking Tutorial: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
Allow the timer fire while the CPU is idle
Line 99:
Essentially; you just need to set the "next_task" field in the data structure for each task's information in both the code to initialise multi-tasking and the code to create a new task.
 
Once that's done, you can write a "schedule()" function that selects a task to switch to and then switches to the selected task. You only need single line of code to select the next task, like "selected_task = current_task_TCB->next_task;" and you already have a function to switch to a specific task; and both of these things can be combined. In other words, the "Schedule()" function can contain a single likeline of code like "switch_to_task(current_task_TCB->next_task);".
 
As soon as you've finished implementing "schedule()" you can test it using the kernel tasks you were using for testing earlier, just by replacing the calls to "switch_to_task()" with calls to "schedule()". If you had multiple additional kernel tasks with different code for each kernel task (so it could switch to the right next task) you can also delete the duplicates so that you end up with multiple additional kernel tasks executing the same code.
 
 
==Step 3: Time Accounting (Optional)==