-diff -X pat -urpN pintos.orig/src/threads/synch.c pintos/src/threads/synch.c
---- pintos.orig/src/threads/synch.c 2004-09-19 21:29:53.000000000 -0700
-+++ pintos/src/threads/synch.c 2004-09-27 16:50:14.000000000 -0700
+diff -X pat -urpN threads/synch.c! src/threads/synch.c
+--- src/threads/synch.c~ 2004-09-19 21:29:53.000000000 -0700
++++ src/threads/synch.c 2004-09-27 16:50:14.000000000 -0700
@@ -330,3 +330,35 @@ cond_name (const struct condition *cond)
return cond->name;
+ }
+ lock_release (&latch->monitor_lock);
+}
-diff -X pat -urpN pintos.orig/src/threads/synch.h pintos/src/threads/synch.h
---- pintos.orig/src/threads/synch.h 2004-09-19 21:29:53.000000000 -0700
-+++ pintos/src/threads/synch.h 2004-09-27 16:50:14.000000000 -0700
+diff -X pat -urpN src/threads/synch.h~ src/threads/synch.h
+--- src/threads/synch.h~ 2004-09-19 21:29:53.000000000 -0700
++++ src/threads/synch.h 2004-09-27 16:50:14.000000000 -0700
@@ -44,4 +44,16 @@ void cond_signal (struct condition *, st
void cond_broadcast (struct condition *, struct lock *);
const char *cond_name (const struct condition *);
+void latch_release (struct latch *);
+
#endif /* threads/synch.h */
-diff -X pat -urpN pintos.orig/src/threads/thread.c pintos/src/threads/thread.c
---- pintos.orig/src/threads/thread.c 2004-09-26 14:15:17.000000000 -0700
-+++ pintos/src/threads/thread.c 2004-09-27 16:51:03.000000000 -0700
+diff -X pat -urpN src/threads/thread.c~ src/threads/thread.c
+--- src/threads/thread.c~ 2004-09-26 14:15:17.000000000 -0700
++++ src/threads/thread.c 2004-09-27 16:51:03.000000000 -0700
@@ -80,6 +80,7 @@ thread_init (void)
init_thread (initial_thread, "main", PRI_DEFAULT);
initial_thread->status = THREAD_RUNNING;
thread_exit (void)
{
+ struct thread *t = thread_current ();
-+ list_elem *e;
++ list_elem *e, *next;
+
ASSERT (!intr_context ());
+ 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);
+ }
schedule ();
NOT_REACHED ();
}
-@@ -270,6 +290,22 @@ thread_block (void)
- thread_current ()->status = THREAD_BLOCKED;
- schedule ();
- }
-+
-+/* Waits for thread with tid CHILD_TID to die. */
-+void
+@@ -283,8 +290,18 @@ thread_block (void)
+ This function will be implemented in problem 1-2. For now, it
+ does nothing. */
+ void
+-thread_join (tid_t child_tid UNUSED)
+-{
+thread_join (tid_t child_tid)
+{
+ struct thread *cur = thread_current ();
+ if (child->tid == child_tid)
+ latch_acquire (&child->ready_to_die);
+ }
-+}
- \f
- /* Idle thread. Executes when no other thread is ready to run. */
- static void
+ }
+
+ /* Sets the current thread's priority to NEW_PRIORITY. */
@@ -335,6 +371,9 @@ init_thread (struct thread *t, const cha
strlcpy (t->name, name, sizeof t->name);
t->stack = (uint8_t *) t + PGSIZE;
t->magic = THREAD_MAGIC;
}
-diff -X pat -urpN pintos.orig/src/threads/thread.h pintos/src/threads/thread.h
---- pintos.orig/src/threads/thread.h 2004-09-26 14:15:17.000000000 -0700
-+++ pintos/src/threads/thread.h 2004-09-27 16:50:14.000000000 -0700
+diff -X pat -urpN src/threads/thread.h~ src/threads/thread.h
+--- src/threads/thread.h~ 2004-09-26 14:15:17.000000000 -0700
++++ src/threads/thread.h 2004-09-27 16:50:14.000000000 -0700
@@ -4,6 +4,7 @@
#include <debug.h>
#include <list.h>