Try to clarify synchronization.
[pintos-anon] / doc / threads.texi
index 06a902f74b3ad0305865e4ca3ba6f03564fbb246..0b6bd701ff70acb6859c264959506acf8b14ae9a 100644 (file)
@@ -332,41 +332,60 @@ and options @option{-j} and @option{-r} are mutually exclusive.
 @node Tips
 @section Tips
 
-There should be no busy-waiting in any of your solutions to this
-assignment.
-
-Do your best to resist the temptation to directly disable interrupts
-in your solution by calling @func{intr_disable} or
-@func{intr_set_level}, although you may find doing so to be useful
-while debugging.  Instead, use semaphores, locks and condition
-variables to solve synchronization problems.  Read the tour section on
-synchronization (@pxref{Synchronization}) or the comments in
-@file{threads/synch.h} if you're unsure what synchronization
-primitives may be used in what situations.
-
-Given some designs of some problems, there may be one or two instances
-in which it is appropriate to directly change the interrupt levels
-instead of relying on the given synchronization primitives.  This must
-be justified in your @file{DESIGNDOC} file.  If you're not sure you're
-justified, ask!
-
-While all parts of this assignment are required if you intend to earn
-full credit on this project, keep in mind that Problem 1-2 (Join) will
-be needed for future assignments, so you'll want to get this one
-right.  We don't give out solutions, so you're stuck with your Join
-code for the whole quarter.  Problem 1-1 (Alarm Clock) could be very
-handy, but not strictly required in the future.  The upshot of all
-this is that you should focus heavily on making sure that your
-implementation of @func{thread_join} works correctly, since if it's
-broken, you will need to fix it for future assignments.  The other
-parts can be turned off in the future if you find you can't make them
-work quite right.
-
-Also keep in mind that Problem 1-4 (the MLFQS) builds on the features you
-implement in Problem 1-3, so to avoid unnecessary code duplication, it
+@itemize @bullet
+@item
+There should be no busy waiting in any of your solutions to this
+assignment.  We consider a tight loop that calls @func{thread_yield}
+to be one form of busy waiting.
+
+@item
+Proper synchronization is an important part of the solutions to these
+problems.  It is tempting to synchronize all your code by turning off
+interrupts with @func{intr_disable} or @func{intr_set_level}, because
+this eliminates concurrency and thus the possibility for race
+conditions, but @strong{don't}.  Instead, use semaphores, locks, and
+condition variables to solve the bulk of your synchronization
+problems.  Read the tour section on synchronization
+(@pxref{Synchronization}) or the comments in @file{threads/synch.c} if
+you're unsure what synchronization primitives may be used in what
+situations.
+
+You might run into a few situations where interrupt disabling is the
+best way to handle synchronization.  If so, you need to explain your
+rationale in your design documents.  If you're unsure whether a given
+situation justifies disabling interrupts, talk to the TAs, who can
+help you decide on the right thing to do.
+
+Disabling interrupts can be useful for debugging, if you want to make
+sure that a section of code is not interrupted.  You should remove
+debugging code before turning in your project.
+
+@item
+All parts of this assignment are required if you intend to earn full
+credit on this project.  However, some will be more important in
+future projects:
+
+@itemize @minus
+@item
+Problem 1-1 (Alarm Clock) could be handy for later projects, but it is
+not strictly required.
+
+@item
+Problem 1-2 (Join) will be needed for future projects.  We don't give
+out solutions, so to avoid extra work later you should make sure that
+your implementation of @func{thread_join} works correctly.
+
+@item
+Problems 1-3 and 1-4 won't be needed for later projects.
+@end itemize
+
+@item
+Problem 1-4 (MLFQS) builds on the features you
+implement in Problem 1-3.  To avoid unnecessary code duplication, it
 would be a good idea to divide up the work among your team members
 such that you have Problem 1-3 fully working before you begin to tackle
 Problem 1-4.
+@end itemize
 
 @node Problem 1-1 Alarm Clock
 @section Problem 1-1: Alarm Clock
@@ -417,8 +436,8 @@ Incidentally, we don't use @code{struct thread *} as
 @func{thread_join}'s parameter type because a thread pointer is not
 unique over time.  That is, when a thread dies, its memory may be,
 whether immediately or much later, reused for another thread.  If
-thread A over time had two children B and C that were stored at the
-same address, then @code{thread_join(@var{B})} and
+thread @var{A} over time had two children @var{B} and @var{C} that
+were stored at the same address, then @code{thread_join(@var{B})} and
 @code{thread_join(@var{C})} would be ambiguous.  Introducing a thread
 id or @dfn{tid}, represented by type @code{tid_t}, that is
 intentionally unique over time solves the problem.  The provided code
@@ -576,7 +595,7 @@ latency, which can make a machine feel sluggish if taken too far.
 Therefore, in general, setting the interrupt level should be used
 sparingly.  Also, any synchronization problem can be easily solved by
 turning interrupts off, since while interrupts are off, there is no
-concurrency, so there's no possibility for race condition.
+concurrency, so there's no possibility for race conditions.
 
 To make sure you understand concurrency well, we are discouraging you
 from taking this shortcut at all in your solution.  If you are unable