summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2016-09-08 14:22:38 -0400
committerRobert Morris <[email protected]>2016-09-08 14:22:38 -0400
commitd63ac118e817ecab6fd4f890960f4f73b4dfd5e8 (patch)
tree7f7b5326ee8c8bf026c731e19c53dd72eec67175 /proc.c
parent5bf3fbee00fb27cb8cb4eca72dcd9fc4c288ed71 (diff)
downloadxv6-labs-d63ac118e817ecab6fd4f890960f4f73b4dfd5e8.tar.gz
xv6-labs-d63ac118e817ecab6fd4f890960f4f73b4dfd5e8.tar.bz2
xv6-labs-d63ac118e817ecab6fd4f890960f4f73b4dfd5e8.zip
this might fix the reported deadlock, though I can't reproduce it.
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/proc.c b/proc.c
index 9e95529..eee79af 100644
--- a/proc.c
+++ b/proc.c
@@ -82,6 +82,12 @@ userinit(void)
acquire(&ptable.lock);
p = allocproc();
+
+ // release the lock in case namei() sleeps.
+ // the lock isn't needed because no other
+ // thread will look at an EMBRYO proc.
+ release(&ptable.lock);
+
initproc = p;
if((p->pgdir = setupkvm()) == 0)
panic("userinit: out of memory?");
@@ -99,6 +105,12 @@ userinit(void)
safestrcpy(p->name, "initcode", sizeof(p->name));
p->cwd = namei("/");
+ // this assignment to p->state lets other cores
+ // run this process. the acquire forces the above
+ // writes to be visible, and the lock is also needed
+ // because the assignment might not be atomic.
+ acquire(&ptable.lock);
+
p->state = RUNNABLE;
release(&ptable.lock);
@@ -141,6 +153,8 @@ fork(void)
return -1;
}
+ release(&ptable.lock);
+
// Copy process state from p.
if((np->pgdir = copyuvm(proc->pgdir, proc->sz)) == 0){
kfree(np->kstack);
@@ -165,6 +179,8 @@ fork(void)
pid = np->pid;
+ acquire(&ptable.lock);
+
np->state = RUNNABLE;
release(&ptable.lock);
@@ -227,7 +243,7 @@ wait(void)
acquire(&ptable.lock);
for(;;){
- // Scan through table looking for zombie children.
+ // Scan through table looking for exited children.
havekids = 0;
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if(p->parent != proc)