story is more complex than I thought.

This commit is contained in:
Robert Morris 2019-09-23 07:24:41 -04:00
parent d175beadf5
commit 37df68e5de

View file

@ -336,18 +336,21 @@ exit(int status)
end_op(); end_op();
p->cwd = 0; p->cwd = 0;
// we might re-parent a child to init. we can't be precise // we might re-parent a child to init. we can't be precise about
// about waking up init, since we can't acquire its lock once // waking up init, since we can't acquire its lock once we've
// we've acquired any other proc lock. so wake up init whether // acquired any other proc lock. so wake up init whether that's
// that's necessary or not. init may miss this wakeup, // necessary or not. init may miss this wakeup, but that seems
// that that seems harmless. // harmless.
acquire(&initproc->lock); acquire(&initproc->lock);
wakeup1(initproc); wakeup1(initproc);
release(&initproc->lock); release(&initproc->lock);
// grab a copy of p->parent, to ensure that we unlock the // grab a copy of p->parent, to ensure that we unlock the same
// same parent we locked. in case our parent gives us away // parent we locked. in case our parent gives us away to init while
// to init while we're waiting for the parent lock. // we're waiting for the parent lock. we may then race with an
// exiting parent, but the result will be a harmless spurious wakeup
// to a dead or wrong process; proc structs are never re-allocated
// as anything else.
acquire(&p->lock); acquire(&p->lock);
struct proc *original_parent = p->parent; struct proc *original_parent = p->parent;
release(&p->lock); release(&p->lock);