exit: fix deadlock

This commit is contained in:
Matheus
2022-10-17 20:43:20 -03:00
parent bfabb9f2dc
commit e0953cd1b0
+10 -7
View File
@@ -9,6 +9,10 @@
void syscall_exit(int status){ void syscall_exit(int status){
proc_t* proc = arch_getcls()->thread->proc; proc_t* proc = arch_getcls()->thread->proc;
proc_t* init = sched_getinit();
spinlock_acquire(&init->lock);
spinlock_acquire(&proc->lock); spinlock_acquire(&proc->lock);
// TODO make all other threads exit // TODO make all other threads exit
@@ -26,25 +30,23 @@ void syscall_exit(int status){
vfs_close(proc->root); vfs_close(proc->root);
vfs_close(proc->cwd); vfs_close(proc->cwd);
proc_t* init = sched_getinit();
spinlock_acquire(&init->lock);
proc_t* child = proc->child; proc_t* child = proc->child;
proc_t* firstchild = child; proc_t* firstchild = child;
while(child){ while(child){
spinlock_acquire(&child->lock); spinlock_acquire(&child->lock);
child->parent = init; child->parent = init;
proc_t* oldc = child;
proc_t* oldsibling = oldc->sibling;
if(!child->sibling){ if(!child->sibling){
child->sibling = init->child; child->sibling = init->child;
init->child = firstchild; init->child = firstchild;
} }
spinlock_release(&child->lock);
child = child->sibling; child = oldsibling;
spinlock_release(&oldc->lock);
} }
spinlock_release(&init->lock);
event_signal(&proc->parent->childevent, true); event_signal(&proc->parent->childevent, true);
// context and thread destruction will happen in the waitpid() // context and thread destruction will happen in the waitpid()
@@ -55,6 +57,7 @@ void syscall_exit(int status){
arch_interrupt_disable(); arch_interrupt_disable();
spinlock_release(&proc->lock); spinlock_release(&proc->lock);
spinlock_release(&init->lock);
sched_dequeue(); sched_dequeue();