Multi-tasking

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
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Multi-tasking

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:12 pm, edited 2 times in total.
DarylD

Re:Multi-Tasking!

Post by DarylD »

I will have to give the standard answer:

*DON'T* even think about coding a scheduler without knowing how it theoretically works, you will get in a terrible mess.

Buy a good book!

Essentially though, the PIT ticks at 100/1000Hz, you switch tasks when this triggers (if you can), saving the state of the current task and loading the state of the next task (including stack/registers). You could use TSS based switching or software (which I am using because it is simpler and faster). You need to ensure that switching won't bugger things up so you may need critical sections protected and even delay switching if certain conditions are true (maybe certain locks held).
Schol-R-LEA

Re:Multi-Tasking!

Post by Schol-R-LEA »

I have to concur with DarylD on this, but I'm sure you were expecting that. Even if you can't buy or borrow one, there is always the online version of Operating Systems Vade Mecum free for download.

I will say that you would be better off in the immediate term writing your task switching and scheduling code, and testing it in cooperative mode (i.e., task switches occur only when a task voluntarily cedes control, or when an interrupt is raised) first. Since pre-emptive multitasking is a superset of cooperative, it should be fairly easy to extend the system to pre-emptive operation once you're sure that the task switching and task scheduling are working correctly.
jrfritz

Re:Multi-Tasking!

Post by jrfritz »

Perica...the Memory Manager is next after the IDT ;)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Multi-Tasking!

Post by Pype.Clicker »

Here's what i can offer :
Clicker Threads programming : that's how i implemented multitasking in my OS
semaphores implementation
the dispatcher doing the job of executing things one after another
default scheduler adding/removing threads from the queues of the dispatcher.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Multi-Tasking!

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 8:12 pm, edited 1 time in total.
hanoi

Re:Multi-Tasking!

Post by hanoi »

How does a program get stopped in the middle of execution? Wouldn't data get lost?
No, you put the registers to the stack and change the address-space like setCR3(Task.PageDirAddress);

And when the OS returns to the task - how does it know where to continue executing?
When the intterupt comes(from IRQ0), the flags and CS and EIP will be put to stack, if you do iret they'll be restored
Post Reply