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:
parent
d404e9e9f8
commit
86f323290c
2 changed files with 11 additions and 11 deletions
|
@ -908,12 +908,12 @@ procread(Chan *c, void *va, long n, vlong off)
|
||||||
}
|
}
|
||||||
|
|
||||||
lock(&p->exl);
|
lock(&p->exl);
|
||||||
if(up == p && p->nchild == 0 && p->waitq == 0) {
|
pid = p->pid;
|
||||||
|
while(p->waitq == 0) {
|
||||||
|
if(up == p && p->nchild == 0) {
|
||||||
unlock(&p->exl);
|
unlock(&p->exl);
|
||||||
error(Enochild);
|
error(Enochild);
|
||||||
}
|
}
|
||||||
pid = p->pid;
|
|
||||||
while(p->waitq == 0) {
|
|
||||||
unlock(&p->exl);
|
unlock(&p->exl);
|
||||||
sleep(&p->waitr, haswaitq, p);
|
sleep(&p->waitr, haswaitq, p);
|
||||||
if(p->pid != pid)
|
if(p->pid != pid)
|
||||||
|
|
|
@ -1229,15 +1229,15 @@ pwait(Waitmsg *w)
|
||||||
}
|
}
|
||||||
|
|
||||||
lock(&up->exl);
|
lock(&up->exl);
|
||||||
if(up->nchild == 0 && up->waitq == 0) {
|
while(up->waitq == 0) {
|
||||||
|
if(up->nchild == 0) {
|
||||||
unlock(&up->exl);
|
unlock(&up->exl);
|
||||||
error(Enochild);
|
error(Enochild);
|
||||||
}
|
}
|
||||||
unlock(&up->exl);
|
unlock(&up->exl);
|
||||||
|
|
||||||
sleep(&up->waitr, haswaitq, up);
|
sleep(&up->waitr, haswaitq, up);
|
||||||
|
|
||||||
lock(&up->exl);
|
lock(&up->exl);
|
||||||
|
}
|
||||||
wq = up->waitq;
|
wq = up->waitq;
|
||||||
up->waitq = wq->next;
|
up->waitq = wq->next;
|
||||||
up->nwait--;
|
up->nwait--;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue