From 17cc40f2d4d462e144952c2459877d4e5e37382b Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 14 Oct 2004 00:43:07 +0000 Subject: [PATCH] Fix race condition. --- solutions/p1-2.patch | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/solutions/p1-2.patch b/solutions/p1-2.patch index b7e9c79..a2a040d 100644 --- a/solutions/p1-2.patch +++ b/solutions/p1-2.patch @@ -76,12 +76,12 @@ diff -X pat -urpN pintos.orig/src/threads/thread.c pintos/src/threads/thread.c /* Stack frame for kernel_thread(). */ kf = alloc_frame (t, sizeof *kf); -@@ -224,16 +226,33 @@ thread_tid (void) +@@ -224,16 +226,34 @@ thread_tid (void) void thread_exit (void) { + struct thread *t = thread_current (); -+ list_elem *e; ++ list_elem *e, *next; + ASSERT (!intr_context ()); @@ -93,10 +93,11 @@ diff -X pat -urpN pintos.orig/src/threads/thread.c pintos/src/threads/thread.c + latch_release (&t->ready_to_die); + + /* Notify our children that they can die. */ -+ for (e = list_begin (&t->children); e != list_end (&t->children); -+ e = list_next (e)) ++ for (e = list_begin (&t->children); e != list_end (&t->children); e = next) + { + struct thread *child = list_entry (e, struct thread, children_elem); ++ next = list_next (e); ++ list_remove (e); + sema_up (&child->can_die); + } + -- 2.30.2