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(). */
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);

View file

@ -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. */

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);
// 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. */

View file

@ -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;
@ -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