wait: always check up->nchild before going to sleep

always make sure that there are child processes we can wait for
before sleeping.

put pwait() sleep into a loop and recheck. this is not strictly
neccesary but prevents accidents if there are spurious wakeups
or a bug.
This commit is contained in:
cinap_lenrek 2012-08-24 13:11:04 +02:00
parent d404e9e9f8
commit 86f323290c
2 changed files with 11 additions and 11 deletions

View file

@ -908,12 +908,12 @@ procread(Chan *c, void *va, long n, vlong off)
}
lock(&p->exl);
if(up == p && p->nchild == 0 && p->waitq == 0) {
unlock(&p->exl);
error(Enochild);
}
pid = p->pid;
while(p->waitq == 0) {
if(up == p && p->nchild == 0) {
unlock(&p->exl);
error(Enochild);
}
unlock(&p->exl);
sleep(&p->waitr, haswaitq, p);
if(p->pid != pid)

View file

@ -1229,15 +1229,15 @@ pwait(Waitmsg *w)
}
lock(&up->exl);
if(up->nchild == 0 && up->waitq == 0) {
while(up->waitq == 0) {
if(up->nchild == 0) {
unlock(&up->exl);
error(Enochild);
}
unlock(&up->exl);
error(Enochild);
sleep(&up->waitr, haswaitq, up);
lock(&up->exl);
}
unlock(&up->exl);
sleep(&up->waitr, haswaitq, up);
lock(&up->exl);
wq = up->waitq;
up->waitq = wq->next;
up->nwait--;