From: Ben Pfaff Date: Mon, 7 Feb 2005 05:56:04 +0000 (+0000) Subject: Get rid of THREAD_JOIN_IMPLEMENTED by adding thread_join() stub. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18654de05aa2c2fa2cc63e2c9c30b9dc536a33d7;p=pintos-anon Get rid of THREAD_JOIN_IMPLEMENTED by adding thread_join() stub. Also add stub implementations of thread_get_priority() and thread_set_priority(). --- diff --git a/doc/filesys.texi b/doc/filesys.texi index b71974f..02808bb 100644 --- a/doc/filesys.texi +++ b/doc/filesys.texi @@ -21,9 +21,6 @@ parts work together so that you can run VM and your filesystem at the same time. Plus, keeping VM is a great way to stress-test your filesystem implementation. -Your submission should define @code{THREAD_JOIN_IMPLEMENTED} in -@file{constants.h} (@pxref{Conditional Compilation}). - @menu * File System New Code:: * File System Synchronization:: diff --git a/doc/standards.texi b/doc/standards.texi index 5b5d502..2582e5c 100644 --- a/doc/standards.texi +++ b/doc/standards.texi @@ -77,11 +77,6 @@ compile properly without the need for any new macros to be defined. There are a few exceptions: @itemize @bullet -@item -Problem 1-2, @func{thread_join}. Some other code expects -@code{THREAD_JOIN_IMPLEMENTED} to be defined once you've implemented -this function. - @item Problem 1-4, the advanced scheduler. We must be able to turn this on and off with a compile-time directive. You must use the macro name we diff --git a/doc/threads.texi b/doc/threads.texi index 44066d2..1905707 100644 --- a/doc/threads.texi +++ b/doc/threads.texi @@ -502,10 +502,6 @@ Write test code that demonstrates the cases your join works for. Be careful to program this function correctly. You will need its functionality for project 2. -Once you've implemented @func{thread_join}, define -@code{THREAD_JOIN_IMPLEMENTED} in @file{constants.h}. -@xref{Conditional Compilation}, for more information. - @node Problem 1-3 Priority Scheduling @section Problem 1-3: Priority Scheduling diff --git a/doc/userprog.texi b/doc/userprog.texi index 9db0737..fa3b4b8 100644 --- a/doc/userprog.texi +++ b/doc/userprog.texi @@ -15,9 +15,7 @@ other part of the code for this assignment. We will describe the relevant parts below. If you are confident in your HW1 code, you can build on top of it. However, if you wish you can start with a fresh copy of the code and re-implement @func{thread_join}, which is the -only part of project #1 required for this assignment. Your submission -should define @code{THREAD_JOIN_IMPLEMENTED} in @file{constants.h} -(@pxref{Conditional Compilation}). +only part of project #1 required for this assignment. Up to now, all of the code you have written for Pintos has been part of the operating system kernel. This means, for example, that all the diff --git a/doc/vm.texi b/doc/vm.texi index 90d407d..fe94820 100644 --- a/doc/vm.texi +++ b/doc/vm.texi @@ -38,9 +38,6 @@ introduced in this project. You will continue to handle Pintos disks and file systems the same way you did in the previous assignment (@pxref{Using the File System}). -Your submission should define @code{THREAD_JOIN_IMPLEMENTED} in -@file{constants.h} (@pxref{Conditional Compilation}). - @menu * VM Design:: * Page Faults:: diff --git a/grading/lib/Pintos/Grading.pm b/grading/lib/Pintos/Grading.pm index 463d475..6a21d52 100644 --- a/grading/lib/Pintos/Grading.pm +++ b/grading/lib/Pintos/Grading.pm @@ -138,10 +138,9 @@ sub extract_sources { LOG => $stem, DIE => "applying patch $stem failed\n"); } - # Install default pintos/src/constants.h. + # Install default pintos/src/constants.h (which is empty). open (CONSTANTS, ">pintos/src/constants.h") or die "constants.h: create: $!\n"; - print CONSTANTS "#define THREAD_JOIN_IMPLEMENTED 1\n"; close CONSTANTS; } diff --git a/solutions/p1-2.patch b/solutions/p1-2.patch index 7e38582..dfae038 100644 --- a/solutions/p1-2.patch +++ b/solutions/p1-2.patch @@ -112,13 +112,12 @@ diff -X pat -urpN src/threads/thread.c~ src/threads/thread.c 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 (); @@ -131,10 +130,9 @@ diff -X pat -urpN src/threads/thread.c~ src/threads/thread.c + if (child->tid == child_tid) + latch_acquire (&child->ready_to_die); + } -+} - - /* 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; diff --git a/solutions/p1-3.patch b/solutions/p1-3.patch index 81bca57..dc54595 100644 --- a/solutions/p1-3.patch +++ b/solutions/p1-3.patch @@ -162,7 +162,7 @@ diff -u -p -u -r1.48 thread.c t->status = THREAD_READY; intr_set_level (old_level); } -@@ -266,11 +280,79 @@ thread_yield (void) +@@ -266,8 +280,8 @@ thread_yield (void) ASSERT (!intr_context ()); old_level = intr_disable (); @@ -172,6 +172,23 @@ diff -u -p -u -r1.48 thread.c schedule (); intr_set_level (old_level); } +@@ -274,19 +288,74 @@ + { + } + +-/* Sets the current thread's priority to NEW_PRIORITY. */ +-void +-thread_set_priority (int new_priority) +-{ +- thread_current ()->priority = new_priority; +-} +- +-/* Returns the current thread's priority. */ +-int +-thread_get_priority (void) +-{ +- return thread_current ()->priority; +-} + +/* Sets the current thread's priority to PRIORITY. */ +void diff --git a/solutions/p2.patch b/solutions/p2.patch index 578ff5e..1de7f57 100644 --- a/solutions/p2.patch +++ b/solutions/p2.patch @@ -1,16 +1,3 @@ -Index: src/constants.h -=================================================================== -RCS file: /afs/ir.stanford.edu/users/b/l/blp/private/cvs/pintos/src/constants.h,v -retrieving revision 1.4 -diff -u -p -r1.4 constants.h ---- src/constants.h 19 Oct 2004 17:37:30 -0000 1.4 -+++ src/constants.h 1 Jan 2005 02:13:41 -0000 -@@ -8,4 +8,4 @@ - /*#define MACRONAME 1 */ - - /* Uncomment if if you've implemented thread_join(). */ --/*#define THREAD_JOIN_IMPLEMENTED 1*/ -+#define THREAD_JOIN_IMPLEMENTED 1 Index: src/threads/synch.c =================================================================== RCS file: /afs/ir.stanford.edu/users/b/l/blp/private/cvs/pintos/src/threads/synch.c,v @@ -157,12 +144,12 @@ diff -u -p -r1.48 thread.c schedule (); NOT_REACHED (); } -@@ -300,6 +323,26 @@ kernel_thread (thread_func *function, vo - function (aux); /* Execute the thread function. */ - thread_exit (); /* If function() returns, kill the thread. */ - } -+ -+/* Waits for thread with tid CHILD_TID to die. */ +@@ -283,8 +290,22 @@ 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) +-{ +int +thread_join (tid_t child_tid) +{ @@ -176,14 +163,13 @@ diff -u -p -r1.48 thread.c + if (child->tid == child_tid) + { + latch_acquire (&child->ready_to_die); -+ return child->exit_code; ++ return child->exit_code; + } + } + return -1; -+} - - /* Returns the running thread. */ - struct thread * + } + + /* Sets the current thread's priority to NEW_PRIORITY. */ @@ -336,6 +379,12 @@ init_thread (struct thread *t, const cha strlcpy (t->name, name, sizeof t->name); t->stack = (uint8_t *) t + PGSIZE; @@ -237,14 +223,14 @@ diff -u -p -r1.28 thread.h /* Owned by thread.c. */ @@ -120,7 +132,7 @@ void thread_exit (void) NO_RETURN; + void thread_exit (void) NO_RETURN; void thread_yield (void); - /* This function will be implemented in problem 1-2. */ -void thread_join (tid_t); +int thread_join (tid_t); - /* These functions will be implemented in problem 1-3. */ void thread_set_priority (int); + int thread_get_priority (void); Index: src/userprog/exception.c =================================================================== RCS file: /afs/ir.stanford.edu/users/b/l/blp/private/cvs/pintos/src/userprog/exception.c,v diff --git a/solutions/p3.patch b/solutions/p3.patch index 078d12a..806177e 100644 --- a/solutions/p3.patch +++ b/solutions/p3.patch @@ -13,15 +13,6 @@ diff -urpN pintos.orig/src/Makefile.build pintos/src/Makefile.build # Filesystem code. filesys_SRC = filesys/filesys.c # Filesystem core. -diff -urpN pintos.orig/src/constants.h pintos/src/constants.h ---- pintos.orig/src/constants.h 2004-09-21 17:26:39.000000000 -0700 -+++ pintos/src/constants.h 2004-09-27 13:29:43.000000000 -0700 -@@ -8,4 +8,4 @@ - /*#define MACRONAME 1 */ - - /* Uncomment if if you've implemented thread_join(). */ --/*#define THREAD_JOIN_IMPLEMENTED 1*/ -+#define THREAD_JOIN_IMPLEMENTED 1 diff -urpN pintos.orig/src/threads/init.c pintos/src/threads/init.c --- pintos.orig/src/threads/init.c 2004-09-26 14:15:17.000000000 -0700 +++ pintos/src/threads/init.c 2004-09-27 16:08:03.000000000 -0700 @@ -183,12 +174,12 @@ diff -urpN pintos.orig/src/threads/thread.c pintos/src/threads/thread.c schedule (); NOT_REACHED (); } -@@ -270,6 +293,26 @@ thread_block (void) - thread_current ()->status = THREAD_BLOCKED; - schedule (); - } -+ -+/* Waits for thread with tid CHILD_TID to die. */ +@@ -283,8 +290,22 @@ 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) +-{ +int +thread_join (tid_t child_tid) +{ @@ -202,14 +193,13 @@ diff -urpN pintos.orig/src/threads/thread.c pintos/src/threads/thread.c + if (child->tid == child_tid) + { + latch_acquire (&child->ready_to_die); -+ return child->ret_code; ++ return child->ret_code; + } + } + return -1; -+} - - /* Idle thread. Executes when no other thread is ready to run. */ - static void + } + + /* Sets the current thread's priority to NEW_PRIORITY. */ @@ -335,6 +378,12 @@ init_thread (struct thread *t, const cha strlcpy (t->name, name, sizeof t->name); t->stack = (uint8_t *) t + PGSIZE; @@ -262,15 +252,15 @@ diff -urpN pintos.orig/src/threads/thread.h pintos/src/threads/thread.h #endif /* Owned by thread.c */ -@@ -119,7 +133,7 @@ void thread_yield (void); - void thread_block (void); +@@ -120,7 +132,7 @@ void thread_exit (void) NO_RETURN; + void thread_exit (void) NO_RETURN; + void thread_yield (void); - /* This function will be implemented in problem 1-2. */ -void thread_join (tid_t); +int thread_join (tid_t); - /* These functions will be implemented in problem 1-3. */ void thread_set_priority (int); + int thread_get_priority (void); diff -urpN pintos.orig/src/userprog/exception.c pintos/src/userprog/exception.c --- pintos.orig/src/userprog/exception.c 2004-09-26 14:15:17.000000000 -0700 +++ pintos/src/userprog/exception.c 2004-09-27 13:29:44.000000000 -0700 diff --git a/src/constants.h b/src/constants.h index 6fca749..8ffe2f6 100644 --- a/src/constants.h +++ b/src/constants.h @@ -6,6 +6,3 @@ /* Example definition. */ /*#define MACRONAME 1 */ - -/* Uncomment if if you've implemented thread_join(). */ -/*#define THREAD_JOIN_IMPLEMENTED 1*/ diff --git a/src/tests/threads/p1-4.c b/src/tests/threads/p1-4.c index 9d66a6f..1f97b2e 100644 --- a/src/tests/threads/p1-4.c +++ b/src/tests/threads/p1-4.c @@ -33,7 +33,6 @@ test (void) static thread_func *funcs[] = {io_thread, cpu_thread, io_cpu_thread}; static const char *names[] = {"IO", "CPU", "IO & CPU"}; struct semaphore done[3]; - tid_t tids[3]; int i; printf ("\n" @@ -43,18 +42,12 @@ test (void) for (i = 0; i < 3; i++) { sema_init (&done[i], 0, names[i]); - tids[i] = thread_create (names[i], PRI_DEFAULT, funcs[i], &done[i]); + thread_create (names[i], PRI_DEFAULT, funcs[i], &done[i]); } /* Wait for threads to finish. */ for (i = 0; i < 3; i++) - { -#ifdef THREAD_JOIN_IMPLEMENTED - thread_join (tids[i]); -#else - sema_down (&done[i]); -#endif - } + sema_down (&done[i]); printf ("Multilevel feedback queue scheduler test done.\n"); } diff --git a/src/threads/init.c b/src/threads/init.c index c17316a..b4b1057 100644 --- a/src/threads/init.c +++ b/src/threads/init.c @@ -123,10 +123,8 @@ main (void) tid_t tid; printf ("\nExecuting '%s':\n", initial_program); tid = process_execute (initial_program); -#ifdef THREAD_JOIN_IMPLEMENTED if (tid != TID_ERROR) thread_join (tid); -#endif } #else /* Run the compiled-in test function. */ diff --git a/src/threads/thread.c b/src/threads/thread.c index 1e5a7d2..ae92e1d 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -273,6 +273,31 @@ thread_yield (void) schedule (); intr_set_level (old_level); } + +/* Waits for the thread with the specified TID to terminate. If + TID has already terminated or TID does not refer to an + immediate child of the current thread, returns immediately. + + This function will be implemented in problem 1-2. For now, it + does nothing. */ +void +thread_join (tid_t child_tid UNUSED) +{ +} + +/* Sets the current thread's priority to NEW_PRIORITY. */ +void +thread_set_priority (int new_priority) +{ + thread_current ()->priority = new_priority; +} + +/* Returns the current thread's priority. */ +int +thread_get_priority (void) +{ + return thread_current ()->priority; +} /* Idle thread. Executes when no other thread is ready to run. */ static void diff --git a/src/threads/thread.h b/src/threads/thread.h index 6fcbfc7..af1f16d 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -119,10 +119,8 @@ const char *thread_name (void); void thread_exit (void) NO_RETURN; void thread_yield (void); -/* This function will be implemented in problem 1-2. */ void thread_join (tid_t); -/* These functions will be implemented in problem 1-3. */ void thread_set_priority (int); int thread_get_priority (void); diff --git a/tests/Makefile b/tests/Makefile index f813f7d..efea7a5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -91,7 +91,6 @@ userprog:: $(prep-grading) $(mk-sandbox) $(apply-patch) ../solutions/p1-2.patch - echo '#define THREAD_JOIN_IMPLEMENTED 1' > $@/pintos/src/constants.h $(run-tests) null $(clean)