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=6070611faac84bdf95c4405b3970c6928202f26b;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/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)