diff --git a/pintos-env/pintos/threads/thread.c b/pintos-env/pintos/threads/thread.c index e3ff6b6..e73f893 100644 --- a/pintos-env/pintos/threads/thread.c +++ b/pintos-env/pintos/threads/thread.c @@ -332,6 +332,15 @@ thread_create (const char *name, int priority, intr_set_level (old_level); + // Update children list on parent and set parent pointer on child + struct thread* cur = thread_current(); + + ASSERT (cur != NULL); + + //printf("Parent thread is: %s. Child is %s\n", cur->name, t->name); + list_push_back(&cur->children, &t->child_elem); + t->parent = cur; + /* Add to run queue. */ thread_unblock (t); @@ -430,6 +439,7 @@ thread_exit (void) list_remove (&t->allelem); thread_current ()->status = THREAD_DYING; sema_up(&t->waiting_sem); + list_remove(&t->child_elem); schedule (); NOT_REACHED (); } @@ -576,6 +586,7 @@ init_thread (struct thread *t, const char *name, int priority) t->stack = (uint8_t *) t + PGSIZE; sema_init(&t->waiting_sem, 0); t->waited_on_before = 0; + list_init(&t->children); if (thread_mlfqs) { t->nice_init = priority > 20 || priority < 20 ? 0 : priority; @@ -717,12 +728,13 @@ schedule (void) struct thread * thread_get_by_tid (tid_t tid) { + struct list* children = &thread_current()->children; struct list_elem *e; - for (e = list_begin (&all_list); - e != list_end (&all_list); + for (e = list_begin (children); + e != list_end (children); e = list_next (e)) { - struct thread *t = list_entry (e, struct thread, allelem); + struct thread *t = list_entry (e, struct thread, child_elem); if (t->tid == tid) return t; } diff --git a/pintos-env/pintos/threads/thread.h b/pintos-env/pintos/threads/thread.h index 8d61d67..d6bdde2 100755 --- a/pintos-env/pintos/threads/thread.h +++ b/pintos-env/pintos/threads/thread.h @@ -100,9 +100,15 @@ struct thread int nice; int nice_init; FPReal recent_cpu; + struct semaphore waiting_sem; + int exit_status; int waited_on_before; + + struct thread* parent; + struct list_elem child_elem; + struct list children; #ifdef USERPROG /* Owned by userprog/process.c. */ diff --git a/pintos-env/pintos/userprog/process.c b/pintos-env/pintos/userprog/process.c index 63b1286..d6e9412 100755 --- a/pintos-env/pintos/userprog/process.c +++ b/pintos-env/pintos/userprog/process.c @@ -63,6 +63,7 @@ process_execute (const char *file_name) tid = thread_create (program_name, PRI_DEFAULT, start_process, fn_copy); if (tid == TID_ERROR) palloc_free_page (fn_copy); + return tid; }