Page 1 of 1

Scheduler schedules itself too?

Posted: Sat Oct 08, 2011 8:53 am
by skandalOS
I can not imagine how the scheduler really works.

It schedules and manages the threads/processes in sequence and knows also about for example how long
to wait for one process and so on. Is that true that Scheduler schedules itself too?
is there a circuit like this:
thread1()
scheduler()
blabla()
scheduler()
blabla
scheduler()
?

Timer Interrupt
for example: if one thread or whatever say wait 30 seconds, the scheduler knows now he has to wait 30 seconds, and the actual time
is 10 + 30 = 40(time to wake this thread again)

There is a little problem, what will happen if the timer interrupt is disabled in this stage for a while, the time isn't true any more
because you lose time(let's say 5 seconds) when the timer does not increment any more.

Can you help me please?

Thanks before

Re: Scheduler schedules itself too?

Posted: Sat Oct 08, 2011 9:22 am
by Rusky
Traditionally, the scheduler is in the kernel, and it gets called by the timer interrupt to decide which process to switch to. That is somewhat like scheduling itself as allowing a process to run for some amount of time lets the scheduler run as well.

I'm not sure what you're getting at with the 10 + 30 = 40 thing. If for some reason you added time to the amount the thread wanted to sleep, it would sleep longer than it expected. If for some reason you disabled the timer interrupt and didn't take that into account, the process would again sleep longer than expected. What is your point/question?

Re: Scheduler schedules itself too?

Posted: Sat Oct 08, 2011 11:13 am
by rdos
The scheduler gets control based on events in the system. It can be that the current thread gives up it's time-slice because it needs to wait for something, or that a higher priority thread becomes ready to run. And then it also can make sure that the current thread does not run forever, which it does by programming a timer that passes control to it when it expires so it can let other threads run even in the presence of uncooperative threads.

So, no, I don't see the scheduler as something that is scheduled. It is an event handler, not a job / task.