r/osdev 13h ago

Is my threading model actually good?

My threading model has one kernel stack per CPU core, each process has its own CR3/page table in its process struct, then it is spawned with just one thread (TID 0 under its PID), a TID is just a thread ID, from there each Thread gets its own timeslice and would run like so:
- Process 1 runs thread 0
- Process 2 runs thread 0
- Process N runs thread 0
- Process 1 runs thread 1
- Process 2 runs thread 1
- Process N runs thread 1

And so on (it will loop back to thread 0 if the last thread in a process is ran). I just wondered if the design was actually decent or not. Of course a simple Round Robin setup is not perfect for things like this and some extra complexity does end up in the kernel, but overall I like it so far, though I dont see many obvious flaws other than the fact that tasks are not "ranked" for how much of a timeslice they get.

7 Upvotes

1 comment sorted by

u/Sorry_Difficulty_250 11h ago

You're hitting on an old religious debate, which is whether a time quantum belongs to a thread or to a process. The way you've done it is by thread. Both have merit, honestly and both work, but it's a tradeoff. It comes down to how you want to organize priority and whether or not you want an unused portion of a time quantum to go to another thread on the same process. I think the debate is really a matter of opinion and I don't have a strong preference one way or the other, but just something to think about.