What kind of scheduler should I use?

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
GhostedGaming
Member
Member
Posts: 35
Joined: Wed Jul 02, 2025 11:46 pm
Libera.chat IRC: GhostedGaming

What kind of scheduler should I use?

Post by GhostedGaming »

So I want priority based scheduling and I'm currently in between making a priority based round robin or something else
here is the project the I'm making for multi-thread and scheduling: https://github.com/GhostedGaming/eclipse-threader
here is my os: https://github.com/GhostedGaming/eclipse-os
go to the overhaul branch
nullplan
Member
Member
Posts: 2034
Joined: Wed Aug 30, 2017 8:24 am

Re: What kind of scheduler should I use?

Post by nullplan »

So what is your question?

There are entire libraries on schedulers. Doubtful I could do an adequate job of summarizing, but you could do a prioritized round-robin like this:
  • Every thread has a static priority and a dynamic priority.
  • The static priority is the one that is set with nice() or setpriority() or such calls.
  • When a thread becomes ready to run, its dynamic priority is initialized to the static priority.
  • Each time the scheduler runs, the dynamic priority is incremented.
  • The scheduler picks the thread with the highest dynamic priority.
  • Whenever a task is picked, its dynamic priority is reset, whether or not it blocks.
This design has several important properties, the most important of which is freedom from starvation. Once a thread is ready to run, its dynamic priority starts growing, and must necessarily at some point become the highest in the system (in the absence of overflows, but that can be controlled with sensible limits on the underlying values).
Carpe diem!
Post Reply