Page 1 of 1

Multi-tasking

Posted: Tue Jan 07, 2003 1:33 am
by Perica
..

Re:Multi-Tasking!

Posted: Tue Jan 07, 2003 3:26 am
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).

Re:Multi-Tasking!

Posted: Tue Jan 07, 2003 10:31 am
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.

Re:Multi-Tasking!

Posted: Tue Jan 07, 2003 11:32 am
by jrfritz
Perica...the Memory Manager is next after the IDT ;)

Re:Multi-Tasking!

Posted: Wed Jan 08, 2003 2:27 am
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.

Re:Multi-Tasking!

Posted: Tue Jan 14, 2003 6:58 am
by Perica
..

Re:Multi-Tasking!

Posted: Tue Jan 14, 2003 9:10 am
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