Page 1 of 1

[Solved]Multitasking

Posted: Sun Sep 04, 2011 8:48 am
by melgmry0101b
Hi everyone: :D
I am going to implement Multitasking in my OS.
now i saw some Wikipedia articles , Wiki articles , JamesM and Google . but i didn't find a useful article that describes and explains the Multitasking <Many of them giving the code then copy and paste>.
Please, Can anyone explains to me how the Multitasking works , Please ?
I want the idea of it and how it works to make my own one :)
-------------------------------------
Thanks in advance.

Re: Multitasking

Posted: Sun Sep 04, 2011 12:05 pm
by miker00lz
Mozo40 wrote:Hi everyone: :D
I am going to implement Multitasking in my OS.
now i saw some Wikipedia articles , Wiki articles , JamesM and Google . but i didn't find a useful article that describes and explains the Multitasking <Many of them giving the code then copy and paste>.
Please, Can anyone explains to me how the Multitasking works , Please ?
I want the idea of it and how it works to make my own one :)
-------------------------------------
Thanks in advance.
the basic idea is that when the kernel decides it's time to pause one process, it saves a snapshot of all registers, flags, and the instruction pointer (it's "context") ... when it's time to resume a process, it restores all of that data, transparently returning control to the process right where it left off.

http://wiki.osdev.org/Multitasking_Systems

Re: Multitasking

Posted: Sun Sep 04, 2011 12:14 pm
by AJ
Hi,

Have a look at Multitasking Systems which gives some background and links.

If you want to think about this so you can do it in your own way, basically think about the "execution context" of your (currently single-tasking) kernel. What basically encompasses everything it needs to run as it does? Initially, this may simply include:
  • Memory Space.
  • General Purpose registers (including (E/R/)IP and the Stack Pointer).
  • Segment Registers
  • (E)FLAGS
Of course, you have to store more than this for housekeeping, such as process ID's, whether the thread is in a waiting or blocked state etc. Later, your implementation may also include things like SSE state and so on

So basically Multitasking involves saving this process state, selecting the next process to run and loading its process state. Again, there is more complexity when you start thinking of things like Multiprocessing, mutual exclusion, task priorities, lock contention and so on. I don't know that I can explain any more about how it works without getting in to implementation details. As you say, there are plenty of practical examples. Although you don't want to copy/paste code, there is absolutely no harm in reading a few code examples to see how it works before deciding how it fits in with your design.

To get a better idea of the theory, you may also be interested to see how it works on a different architecture, such as the 8 bit RISC AVR which can be found here.

Cheers,
Adam

Re: Multitasking

Posted: Sun Sep 04, 2011 3:20 pm
by melgmry0101b
Thank you very much AJ and miker00lz :)