From 020c8e2384877ffc13579f633ac3c723f80baf8c Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Mon, 4 Aug 2014 06:13:49 -0400 Subject: 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 --- proc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'proc.c') diff --git a/proc.c b/proc.c index bcdbfea..e19539c 100644 --- a/proc.c +++ b/proc.c @@ -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"); } } - - -- cgit v1.2.3