我在谈论:
struct {
struct spinlock lock;
struct proc proc[NPROC];
} ptable;
它位于 proc.c 文件中。
有人可以解释它在哪里初始化吗?因为,在 proc.c 中,我从未见过向其中添加某些东西(进程)。
更准确地说,假设我正在查看调度程序代码:
void
scheduler(void)
{
struct proc *p;
for(;;){
// Enable interrupts on this processor.
sti();
// Loop over process table looking for process to run.
acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if(p−>state != RUNNABLE)
continue;
// Switch to chosen process. It is the process’s job
// to release ptable.lock and then reacquire it
// before jumping back to us.
proc = p;
switchuvm(p);
p−>state = RUNNING;
swtch(&cpu−>scheduler, proc−>context);
switchkvm();
// Process is done running for now.
// It should have changed its p−>state before coming back.
proc = 0;
}
release(&ptable.lock);
}
}
在:
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
你可以看到我们正在循环遍历 ptable 中的每个进程。我的问题是,他们是如何到达那里的?谢谢!