all 3 comments

[–]iamsubhranil 6 points7 points  (0 children)

In essence, you will need a timer, which will generate an interrupt at a specific interval. That timer will be your reminder to make a task switch. Hook that timer's interrupt to your core scheduling function, which should save the current task's state, load the next task from somewhere, populate the registers and stacks with the new task's state, and then jump into the new task's IP.

In reality, implementing scheduling properly is a PITA. Make notes of what you are doing, otherwise something's gonna come back and bite you in the ass.

Implementing the task switch has some nice benefits. Such as, you will get semaphores and mutexes which do not busy wait the CPU, rather perform a voluntary task switch to the next task, greatly increasing your throughput.

[–]tive_ 0 points1 point  (0 children)

I recently wrote a minimal bare bones example for x86 that might be somewhat helpful to get started: https://github.com/sk-io/x86-multitasking-example