Wait returns correct status

This commit is contained in:
Claudio Maggioni 2020-05-18 17:12:13 +02:00
parent 77f94f0828
commit 5f2b2114ff
4 changed files with 14 additions and 7 deletions

View file

@ -436,9 +436,11 @@ thread_exit (void)
when it calls thread_schedule_tail(). */ when it calls thread_schedule_tail(). */
intr_disable (); intr_disable ();
struct thread* t = thread_current(); struct thread* t = thread_current();
//printf("Exit status: %d\n",t->exit_status);
list_remove (&t->allelem); list_remove (&t->allelem);
thread_current ()->status = THREAD_DYING;
sema_up(&t->waiting_sem); sema_up(&t->waiting_sem);
sema_down(&t->parent->parent_sem);
t->status = THREAD_DYING;
list_remove(&t->child_elem); list_remove(&t->child_elem);
schedule (); schedule ();
NOT_REACHED (); NOT_REACHED ();
@ -585,6 +587,7 @@ init_thread (struct thread *t, const char *name, int priority)
strlcpy (t->name, name, sizeof t->name); strlcpy (t->name, name, sizeof t->name);
t->stack = (uint8_t *) t + PGSIZE; t->stack = (uint8_t *) t + PGSIZE;
sema_init(&t->waiting_sem, 0); sema_init(&t->waiting_sem, 0);
sema_init(&t->parent_sem, 0);
t->waited_on_before = 0; t->waited_on_before = 0;
list_init(&t->children); list_init(&t->children);

View file

@ -110,6 +110,8 @@ struct thread
struct list_elem child_elem; struct list_elem child_elem;
struct list children; struct list children;
struct semaphore parent_sem;
#ifdef USERPROG #ifdef USERPROG
/* Owned by userprog/process.c. */ /* Owned by userprog/process.c. */
uint32_t *pagedir; /* Page directory. */ uint32_t *pagedir; /* Page directory. */

View file

@ -182,8 +182,6 @@ process_wait (tid_t child_tid)
{ {
//printf("process wait for: %s on: %ul\n", thread_current()->name, 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); struct thread* child = thread_get_by_tid(child_tid);
if (child == NULL || child->waited_on_before) { if (child == NULL || child->waited_on_before) {
//printf("child not found\n"); //printf("child not found\n");
@ -193,8 +191,11 @@ process_wait (tid_t child_tid)
//printf("child is: %s\n", child->name); //printf("child is: %s\n", child->name);
sema_down(&child->waiting_sem); sema_down(&child->waiting_sem);
int status = child->exit_status;
//printf("Wait exit: %s %d\n",child->name, status);
child->waited_on_before = 1; child->waited_on_before = 1;
return child->exit_status; sema_up(&(thread_current()->parent_sem));
return status;
} }
/* Free the current process's resources. */ /* Free the current process's resources. */

View file

@ -23,7 +23,6 @@ void
syscall_init (void) syscall_init (void)
{ {
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
printf("syscall\n");
memset(syscall_vec, (int)&syscall_nop, 128); memset(syscall_vec, (int)&syscall_nop, 128);
syscall_vec[SYS_EXIT] = (handler)sys_exit; syscall_vec[SYS_EXIT] = (handler)sys_exit;
syscall_vec[SYS_WAIT] = (handler)sys_wait; syscall_vec[SYS_WAIT] = (handler)sys_wait;
@ -74,7 +73,9 @@ int
sys_wait (tid_t tid) sys_wait (tid_t tid)
{ {
printf("system call wait\n"); 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 tid_t