don't over-lock in exit()

This commit is contained in:
Robert Morris 2020-11-05 07:32:10 -05:00
parent 7dea4b93c8
commit bc943c2309
2 changed files with 7 additions and 3 deletions

View file

@ -358,14 +358,14 @@ exit(int status)
p->cwd = 0; p->cwd = 0;
acquire(&proc_tree_lock); acquire(&proc_tree_lock);
acquire(&p->lock);
// Give any children to init. // Give any children to init.
reparent(p); reparent(p);
// Parent might be sleeping in wait(). // Parent might be sleeping in wait().
wakeup(p->parent); wakeup(p->parent);
acquire(&p->lock);
p->xstate = status; p->xstate = status;
p->state = ZOMBIE; p->state = ZOMBIE;
@ -393,7 +393,9 @@ wait(uint64 addr)
havekids = 0; havekids = 0;
for(np = proc; np < &proc[NPROC]; np++){ for(np = proc; np < &proc[NPROC]; np++){
if(np->parent == p){ if(np->parent == p){
// make sure the child isn't still in exit() or swtch().
acquire(&np->lock); acquire(&np->lock);
havekids = 1; havekids = 1;
if(np->state == ZOMBIE){ if(np->state == ZOMBIE){
// Found one. // Found one.

View file

@ -88,12 +88,14 @@ struct proc {
// p->lock must be held when using these: // p->lock must be held when using these:
enum procstate state; // Process state enum procstate state; // Process state
struct proc *parent; // Parent process
void *chan; // If non-zero, sleeping on chan void *chan; // If non-zero, sleeping on chan
int killed; // If non-zero, have been killed int killed; // If non-zero, have been killed
int xstate; // Exit status to be returned to parent's wait int xstate; // Exit status to be returned to parent's wait
int pid; // Process ID int pid; // Process ID
// proc_tree_lock must be held when using this:
struct proc *parent; // Parent process
// these are private to the process, so p->lock need not be held. // these are private to the process, so p->lock need not be held.
uint64 kstack; // Virtual address of kernel stack uint64 kstack; // Virtual address of kernel stack
uint64 sz; // Size of process memory (bytes) uint64 sz; // Size of process memory (bytes)