Experiment 1: Nachos Threads 1. Objectives
Experiment 1: Nachos Threads 1. Objectives
EXPERIMENT 1
NACHOS THREADS
1. OBJECTIVES
2. LABORATORY
3. EQUIPMENT
4. WHY NACHOS?
For example, a complete UNIX-like file system would be too complicated for students
to understand in only a few weeks. The approach was to build the simplest
implementation for each sub-system of Nachos; this provides students a working
example, albeit overly simplistic, of the operation of each component of an operating
system. As a result of the emphasis on simplicity, the Nachos operating system is
about 2500 lines of code, about half of which are devoted to interface descriptions
and comments.
Experiment 1 Page 1
CE/CZ2005 Operating Systems (Nachos Threads)
It is thus practical for students to read, understand, and modify Nachos during a
single semester course.
5. NACHOS OVERVIEW
Like many of its predecessor instructional operating systems, the Nachos kernel and
hardware simulator run together in the same UNIX process. Nachos has several
significant differences from earlier systems:
• The simulation is deterministic. Debugging non-repeatable execution sequences
is a fact of life for professional operating systems engineers. Instead of using
UNIX signals to simulate asynchronous devices such as the disk and the timer,
Nachos maintains a simulated time that is incremented whenever a user program
executes an instruction and whenever a call is made to certain low-level
operating system routines. Interrupt handlers are then invoked when the
simulated time reaches the appropriate point.
• Nachos is implemented in a subset of C++. Object-oriented programming is
becoming more popular. It was a natural idiom for stressing the importance of
modularity and clean interfaces in building operating systems. To simplify
matters, certain aspects of the C++ language are omitted: derived classes,
operator and function overloading, and C++ streams.
6. THREAD MANAGEMENT
The thread system is based on FastThreads [8]. The primary goal was simplicity, to
reduce the effort required for students to trace the behavior of the thread system.
In this lab, you are required to read and understand the partial thread system that has
been written for you. This thread system implements thread fork, thread completion,
along with semaphores for synchronization. Run the program Nachos for a simple
test of the code. Trace the execution path (by hand) for the simple test case provided.
When you trace the execution path, it is helpful to keep track of the state of each
thread and which procedures are on each thread's execution stack. You will notice
that when one thread calls SWITCH, another thread starts running, and the first thing
the new thread does is to return from SWITCH. This comment will seem cryptic to you
Experiment 1 Page 2
CE/CZ2005 Operating Systems (Nachos Threads)
at this point, but you will understand threads once you understand why the SWITCH
that gets called is different from the SWITCH that returns.
7. EXERCISES
1. Copy a complete set of Nachos 3.4 source code to your home directory by typing
cp -r /shares/nachos-exp1-2 ~
6. Fill in the following table (one of the example is shown below) whenever:
• the ready list (i.e., ready queue in your textbook) of Nachos is changed, or
• the current thread is changed, or
• a new message is printed in method SimpleTest(int which).
In column ready list, you need to list the names of the threads in the ready
list (with the leftmost being the thread at the front of the queue). Column
current thread should show the current thread. The messages generated in
method SimpleTest(int which) should be provided in column printf
message when appropriate. Fill as many rows as necessary until Nachos exits
(each row corresponds to 10-tick output except the first row).
7. List all context switches occurring in the test run above. Indicate from what thread
to what thread is the context switching.
8. ASSESSMENT
9. QUESTIONS TO PONDER
Experiment 1 Page 3
CE/CZ2005 Operating Systems (Nachos Threads)
10. References
[1] http://homes.cs.washington.edu/~tom/nachos/
[2] http://www.minix3.org/
[3] http://www.multicians.org/
[4] E. W. Dijkstra, Solution of a problem in concurrent programming control,
Communications of the ACM, v.8 n.9, p.569, Sept. 1965
[5] http://www.adahome.com/
[6] http://www.modula3.org/
[7] J.R. Cordy and R.C. Holt 1980. Specification of Concurrent Euclid. Technical
reports CSRI-115 (July 1980) and CSRI-133 (August 1981), Computer Systems
Research Institute, University of Toronto.
[8] Thomas E. Anderson FastThreads User's Manual. University of Washington.
Seattle. January 1990.
Experiment 1 Page 4