use acquire/release to force order for pid=np->pid;np->state=RUNNING

for bug reported by symingz@gmail.com and cs1100254@cse.iitd.ernet.in
This commit is contained in:
Robert Morris 2014-08-04 06:13:49 -04:00
parent 86188d9d49
commit 020c8e2384
3 changed files with 18 additions and 10 deletions

10
proc.c
View file

@ -153,10 +153,16 @@ fork(void)
if(proc->ofile[i])
np->ofile[i] = filedup(proc->ofile[i]);
np->cwd = idup(proc->cwd);
safestrcpy(np->name, proc->name, sizeof(proc->name));
pid = np->pid;
// lock to force the compiler to emit the np->state write last.
acquire(&ptable.lock);
np->state = RUNNABLE;
safestrcpy(np->name, proc->name, sizeof(proc->name));
release(&ptable.lock);
return pid;
}
@ -455,5 +461,3 @@ procdump(void)
cprintf("\n");
}
}