[Solved]Multitasking

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

[Solved]Multitasking

Post 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.
Last edited by melgmry0101b on Sun Sep 04, 2011 3:21 pm, edited 1 time in total.
User avatar
miker00lz
Member
Member
Posts: 144
Joined: Wed Dec 08, 2010 3:16 am
Location: St. Louis, MO USA

Re: Multitasking

Post 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
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Multitasking

Post 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
melgmry0101b
Member
Member
Posts: 109
Joined: Wed Nov 10, 2010 10:49 am

Re: Multitasking

Post by melgmry0101b »

Thank you very much AJ and miker00lz :)
Post Reply