diff --git a/pintos-env/pintos/threads/thread.c b/pintos-env/pintos/threads/thread.c index e73f893..361a083 100644 --- a/pintos-env/pintos/threads/thread.c +++ b/pintos-env/pintos/threads/thread.c @@ -436,9 +436,11 @@ thread_exit (void) when it calls thread_schedule_tail(). */ intr_disable (); struct thread* t = thread_current(); + //printf("Exit status: %d\n",t->exit_status); list_remove (&t->allelem); - thread_current ()->status = THREAD_DYING; sema_up(&t->waiting_sem); + sema_down(&t->parent->parent_sem); + t->status = THREAD_DYING; list_remove(&t->child_elem); schedule (); NOT_REACHED (); @@ -585,6 +587,7 @@ init_thread (struct thread *t, const char *name, int priority) strlcpy (t->name, name, sizeof t->name); t->stack = (uint8_t *) t + PGSIZE; sema_init(&t->waiting_sem, 0); + sema_init(&t->parent_sem, 0); t->waited_on_before = 0; list_init(&t->children); diff --git a/pintos-env/pintos/threads/thread.h b/pintos-env/pintos/threads/thread.h index d6bdde2..95e2666 100755 --- a/pintos-env/pintos/threads/thread.h +++ b/pintos-env/pintos/threads/thread.h @@ -110,6 +110,8 @@ struct thread struct list_elem child_elem; struct list children; + struct semaphore parent_sem; + #ifdef USERPROG /* Owned by userprog/process.c. */ uint32_t *pagedir; /* Page directory. */ diff --git a/pintos-env/pintos/userprog/process.c b/pintos-env/pintos/userprog/process.c index d6e9412..dd5194e 100755 --- a/pintos-env/pintos/userprog/process.c +++ b/pintos-env/pintos/userprog/process.c @@ -182,8 +182,6 @@ process_wait (tid_t child_tid) { //printf("process wait for: %s on: %ul\n", thread_current()->name, child_tid); - // TODO: check if tid is child - struct thread* child = thread_get_by_tid(child_tid); if (child == NULL || child->waited_on_before) { //printf("child not found\n"); @@ -193,8 +191,11 @@ process_wait (tid_t child_tid) //printf("child is: %s\n", child->name); sema_down(&child->waiting_sem); + int status = child->exit_status; + //printf("Wait exit: %s %d\n",child->name, status); child->waited_on_before = 1; - return child->exit_status; + sema_up(&(thread_current()->parent_sem)); + return status; } /* Free the current process's resources. */ diff --git a/pintos-env/pintos/userprog/syscall.c b/pintos-env/pintos/userprog/syscall.c index a0deea0..cfd5b0b 100755 --- a/pintos-env/pintos/userprog/syscall.c +++ b/pintos-env/pintos/userprog/syscall.c @@ -23,7 +23,6 @@ void syscall_init (void) { intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); -printf("syscall\n"); memset(syscall_vec, (int)&syscall_nop, 128); syscall_vec[SYS_EXIT] = (handler)sys_exit; syscall_vec[SYS_WAIT] = (handler)sys_wait; @@ -66,7 +65,7 @@ sys_exit (int status) struct thread* t = thread_current(); printf("%s: exit(%d)\n", t->name, status); t->exit_status = status; - thread_exit (); + thread_exit(); return -1; } @@ -74,7 +73,9 @@ int sys_wait (tid_t tid) { printf("system call wait\n"); - return process_wait(tid); + int status = process_wait(tid); + //printf("wait has returned status(%d)\n", status); + return status; } tid_t