Scheduler schedules itself too?

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
skandalOS
Posts: 15
Joined: Mon Sep 05, 2011 12:05 pm

Scheduler schedules itself too?

Post 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
User avatar
Rusky
Member
Member
Posts: 792
Joined: Wed Jan 06, 2010 7:07 pm

Re: Scheduler schedules itself too?

Post 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?
rdos
Member
Member
Posts: 3310
Joined: Wed Oct 01, 2008 1:55 pm

Re: Scheduler schedules itself too?

Post 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.
Post Reply