2007/4/15, Russ Cox <[EMAIL PROTECTED]>:
/* cooperative scheduling until the clock ticks */
if((p=m->readied) && p->mach==0 && p->state==Ready
&& runq[Nrq-1].head == nil && runq[Nrq-2].head == nil){
The tests are:
p=m->readied
some process p was last readied on this cpu (Mach)
p->mach == 0
p is not running on any cpu right now
Not to be overly annoying, but _is_ it possible that between the
assignment and that test, p->mach is set, indicating another CPU took
over? It just doesn't seem like m->readied is locked, at all; it seems
like another CPU could pick it up in the middle.
p->state == Ready
p is still Ready (waiting to run)
runq[Nrq-1].head == nil && runq[Nrq-2].head == nil
there are no real-time processes waiting to run
If all those succeed, then the code tries to choose
p to run next. But it might not -- the next thing that
happens is
p = dequeueproc(rq, p);
which can return nil if p has already been grabbed
or even if there is contention for the runq lock.
All the accesses in the if condition are just fine --
they happen without a lock but dequeueproc double-checks
that p is okay to schedule.
If dequeueproc returns nil, then runproc won't pick
the readied p after all -- it will fall into the regular
scheduling loop to find a process.
Russ
Thanks for the low-level explanation. It does really help my understanding.
--dho