Mainly historical reasons. A doubly linked list is indeed a better
approach, but the array works well enough.
Actually, the array is seldom used any more: we do have a doubly linked
list as well (next_task/prev_task) and now we also have a doubly linked
list of runnable processes (next_run/prev_run). Most places use the
"for_each_task(p)" macro to go through all the processes.
> I also have a second question about the scheduler. The run queue way just
> added, but I one thing I think can improve it. Why isn't a priority heap
> used for it.
I think a priority heap is probably not worth it: the run-queue is
normally only a few processes deep, so a linked list makes sense (the
overhead of going through 2-3 processes to find the runnable one is
rather small, and doing a heap would make the add/remove operations
slightly more complex).
That said, feel free to try this out in real life: I haven't actually
tried a heap for this.
Linus