wip on hw4
This commit is contained in:
parent
c987ffa0dc
commit
77f94f0828
3 changed files with 22 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue