fix an exit/exit deadlock -> one more locking protocol violation
increase timer rate from 1/second to 10/second
This commit is contained in:
parent
b19adf79f9
commit
4e62de64cd
|
@ -294,9 +294,14 @@ reparent(struct proc *p, struct proc *parent) {
|
||||||
int child_of_init = (p->parent == initproc);
|
int child_of_init = (p->parent == initproc);
|
||||||
|
|
||||||
for(pp = proc; pp < &proc[NPROC]; pp++){
|
for(pp = proc; pp < &proc[NPROC]; pp++){
|
||||||
if (pp != p && pp != parent) {
|
// this code uses pp->parent without holding pp->lock.
|
||||||
acquire(&pp->lock);
|
// acquiring the lock first could cause a deadlock
|
||||||
|
// if pp or a child of pp were also in exit()
|
||||||
|
// and about to try to lock p.
|
||||||
if(pp->parent == p){
|
if(pp->parent == p){
|
||||||
|
// pp->parent can't change between the check and the acquire()
|
||||||
|
// because only the parent changes it, and we're the parent.
|
||||||
|
acquire(&pp->lock);
|
||||||
pp->parent = initproc;
|
pp->parent = initproc;
|
||||||
if(pp->state == ZOMBIE) {
|
if(pp->state == ZOMBIE) {
|
||||||
if(!child_of_init)
|
if(!child_of_init)
|
||||||
|
@ -305,7 +310,6 @@ reparent(struct proc *p, struct proc *parent) {
|
||||||
if(!child_of_init)
|
if(!child_of_init)
|
||||||
release(&initproc->lock);
|
release(&initproc->lock);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
release(&pp->lock);
|
release(&pp->lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,15 +41,16 @@ start()
|
||||||
// which turns them into software interrupts for
|
// which turns them into software interrupts for
|
||||||
// devintr() in trap.c.
|
// devintr() in trap.c.
|
||||||
int id = r_mhartid();
|
int id = r_mhartid();
|
||||||
// ask the CLINT for a timer interrupt 10,000 cycles from now.
|
// ask the CLINT for a timer interrupt.
|
||||||
*(uint64*)CLINT_MTIMECMP(id) = *(uint64*)CLINT_MTIME + 10000;
|
int interval = 1000000; // cycles; about 1/10th second in qemu.
|
||||||
|
*(uint64*)CLINT_MTIMECMP(id) = *(uint64*)CLINT_MTIME + interval;
|
||||||
// prepare information in scratch[] for machinevec.
|
// prepare information in scratch[] for machinevec.
|
||||||
// scratch[0..3] : space for machinevec to save registers.
|
// scratch[0..3] : space for machinevec to save registers.
|
||||||
// scratch[4] : address of CLINT MTIMECMP register.
|
// scratch[4] : address of CLINT MTIMECMP register.
|
||||||
// scratch[5] : desired interval (in cycles) between timer interrupts.
|
// scratch[5] : desired interval (in cycles) between timer interrupts.
|
||||||
uint64 *scratch = &mscratch0[32 * id];
|
uint64 *scratch = &mscratch0[32 * id];
|
||||||
scratch[4] = CLINT_MTIMECMP(id);
|
scratch[4] = CLINT_MTIMECMP(id);
|
||||||
scratch[5] = 10000000;
|
scratch[5] = interval;
|
||||||
w_mscratch((uint64)scratch);
|
w_mscratch((uint64)scratch);
|
||||||
// set the machine-mode trap handler.
|
// set the machine-mode trap handler.
|
||||||
w_mtvec((uint64)machinevec);
|
w_mtvec((uint64)machinevec);
|
||||||
|
@ -61,6 +62,6 @@ start()
|
||||||
// keep each CPU's hartid in its tp register, for cpuid().
|
// keep each CPU's hartid in its tp register, for cpuid().
|
||||||
w_tp(id);
|
w_tp(id);
|
||||||
|
|
||||||
// call main() in supervisor mode.
|
// switch to supervisor mode and jump to main().
|
||||||
asm volatile("mret");
|
asm volatile("mret");
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,7 +448,7 @@ reparent(void)
|
||||||
|
|
||||||
printf(1, "reparent test\n");
|
printf(1, "reparent test\n");
|
||||||
|
|
||||||
for(int i = 0; i < 100; i++){
|
for(int i = 0; i < 200; i++){
|
||||||
int pid = fork();
|
int pid = fork();
|
||||||
if(pid < 0){
|
if(pid < 0){
|
||||||
printf(1, "fork failed\n");
|
printf(1, "fork failed\n");
|
||||||
|
@ -571,10 +571,10 @@ forkforkfork(void)
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(2);
|
sleep(20); // two seconds
|
||||||
close(open("stopforking", O_CREATE|O_RDWR));
|
close(open("stopforking", O_CREATE|O_RDWR));
|
||||||
wait();
|
wait();
|
||||||
sleep(1);
|
sleep(10); // one second
|
||||||
|
|
||||||
printf(1, "forkforkfork ok\n");
|
printf(1, "forkforkfork ok\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue