From 959a4bf51d7350af206dab34141c34a5b1476e57 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 12 Feb 2011 10:03:53 -0800 Subject: [PATCH] thread: Properly protect 'all_list' around insertion. Reported by Francis Russell . --- solutions/p1.patch | 5 ++++- solutions/p3.patch | 8 +++++++- solutions/p4.patch | 8 +++++++- src/threads/thread.c | 5 +++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/solutions/p1.patch b/solutions/p1.patch index 2e039eb..046989f 100644 --- a/solutions/p1.patch +++ b/solutions/p1.patch @@ -654,7 +654,7 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c } /* Idle thread. Executes when no other thread is ready to run. -@@ -467,8 +613,10 @@ +@@ -467,11 +613,13 @@ t->status = THREAD_BLOCKED; strlcpy (t->name, name, sizeof t->name); t->stack = (uint8_t *) t + PGSIZE; @@ -663,7 +663,10 @@ diff -Nur ../../src/threads/thread.c src/threads/thread.c t->magic = THREAD_MAGIC; + sema_init (&t->timer_sema, 0); + list_init (&t->donors); + + old_level = intr_disable (); list_push_back (&all_list, &t->allelem); + intr_set_level (old_level); } @@ -495,8 +643,14 @@ diff --git a/solutions/p3.patch b/solutions/p3.patch index d3a5dde..a62adfd 100644 --- a/solutions/p3.patch +++ b/solutions/p3.patch @@ -186,13 +186,15 @@ diff -u src/threads/thread.c~ src/threads/thread.c #endif /* Remove thread from all threads list, set our status to dying, -@@ -406,17 +410,28 @@ is_thread (struct thread *t) +@@ -406,23 +410,34 @@ is_thread (struct thread *t) /* Does basic initialization of T as a blocked thread named NAME. */ static void -init_thread (struct thread *t, const char *name, int priority) +init_thread (struct thread *t, const char *name, int priority, tid_t tid) { + enum intr_level old_level; + ASSERT (t != NULL); ASSERT (PRI_MIN <= priority && priority <= PRI_MAX); ASSERT (name != NULL); @@ -214,6 +216,10 @@ diff -u src/threads/thread.c~ src/threads/thread.c + list_init (&t->mappings); + t->next_handle = 2; t->magic = THREAD_MAGIC; + + old_level = intr_disable (); + list_push_back (&all_list, &t->allelem); + intr_set_level (old_level); } Index: src/threads/thread.h diff --git a/solutions/p4.patch b/solutions/p4.patch index 36bc258..b94410b 100644 --- a/solutions/p4.patch +++ b/solutions/p4.patch @@ -2134,13 +2134,15 @@ diff -u src/threads/thread.c~ src/threads/thread.c #endif /* Remove thread from all threads list, set our status to dying, -@@ -406,17 +410,29 @@ is_thread (struct thread *t) +@@ -406,23 +410,35 @@ is_thread (struct thread *t) /* Does basic initialization of T as a blocked thread named NAME. */ static void -init_thread (struct thread *t, const char *name, int priority) +init_thread (struct thread *t, const char *name, int priority, tid_t tid) { + enum intr_level old_level; + ASSERT (t != NULL); ASSERT (PRI_MIN <= priority && priority <= PRI_MAX); ASSERT (name != NULL); @@ -2163,6 +2165,10 @@ diff -u src/threads/thread.c~ src/threads/thread.c + t->next_handle = 2; + t->wd = NULL; t->magic = THREAD_MAGIC; + + old_level = intr_disable (); + list_push_back (&all_list, &t->allelem); + intr_set_level (old_level); } Index: src/threads/thread.h diff --git a/src/threads/thread.c b/src/threads/thread.c index 955ccdc..d68c123 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -459,6 +459,8 @@ is_thread (struct thread *t) static void init_thread (struct thread *t, const char *name, int priority) { + enum intr_level old_level; + ASSERT (t != NULL); ASSERT (PRI_MIN <= priority && priority <= PRI_MAX); ASSERT (name != NULL); @@ -469,7 +471,10 @@ init_thread (struct thread *t, const char *name, int priority) t->stack = (uint8_t *) t + PGSIZE; t->priority = priority; t->magic = THREAD_MAGIC; + + old_level = intr_disable (); list_push_back (&all_list, &t->allelem); + intr_set_level (old_level); } /* Allocates a SIZE-byte frame at the top of thread T's stack and -- 2.30.2