Question: For this homework, you will be working with the threads ' subsystem of NACHOS. This is the part of NACHOS that supports multiple concurrent activities
For this homework, you will be working with the "threads" subsystem of NACHOS. This is the part of
NACHOS that supports multiple concurrent activities within the kernel. In the exercises below, you
will write some simple programs that create multiple threads, you will demonstrate the problems that
arise when multiple threads perform unsynchronized access to shared data, and you will rectify
these problems by introducing synchronization in the form of semaphores into the code. Then, you
will implement the lock and condition synchronization primitives that are missing from NACHOS.
Finally, you will simulate two real world synchronization problems by using the synchronization
primitives.
All your work for this assignment will take place within the directory. Although you might
find it helpful to look at files outside this directory, you should not make any changes to files other
than those in the
the beginning:
directory. In general, if a source code file has the following message at
DO NOT CHANGE part of the machine emulation
then you are not to change it All other files are fair game. Sometimes, you may even wish to add
additional source files. This is OK but make sure to make appropriate changes to Makefile.common.
Important! Read This
In this assignment, and in all subsequent assignments in this course, you will be given very detailed
specifications concerning particular functions or classes you are to implement. Though you will
generally have considerable flexibility in exactly how you implement these functions, it is extremely
important that the names of these functions and their behaviors are exactly as specified. If an
assignment tells you to implement a function or class with a particular name andor prototype, do not
implement something with a different name or prototype.
In this course, we are going to perform a great deal of the building and testing of your software
automatically. We will write our own driver functions which we will link with your code. If you adhere
exactly to the specifications, everything should work properly. If not, your code will require manual
intervention to test, and the large number of students in the class will probably make this impossible
for us
One other thing that will make manual intervention necessary is if your code produces extraneous
printout when it runs. You should therefore see to it that your code, as submitted, should produce no
printout other than that originally present in Nachos, or that specifically indicated in the assignment.
In addition, if the assignment specifies that you are to produce printout, your printout must
appear exactly as specified. Do not add extraneous newlines, extra characters, or change in any
way the format of the messages you are told to produce.
You will probably find it useful to incorporate debugging printout into your code during development
and testing. This is OK but all such code should use the NACHOS DEBUG macro defined in
threads
ThreadTest
SimpleThread
threadsutilityh so that debugging printout is not produced unless a suitable commandline flag is
provided. Examples of the use of this macro appear throughout the NACHOS code.
Every time you modify a NACHOS file, you should surround all of your changes with preprocessor
commands that make it easy to compile the code without your changes.
#if definedCHANGED && definedTHREADS
put your changed code here
#else
the original code goes here
#endif
Exercise : Simple Threads Programming Weight:
The purpose of this exercise is for you to get some experience using the threads primitives provided
by NACHOS, and to demonstrate what happens if concurrently executing threads access shared
variables without proper synchronization. Then you will use the semaphore synchronization
primitives in NACHOS to achieve proper synchronization.
When the threads version of NACHOS is started, it initially creates a single thread that begins
executing the function
calls the function
in the file threadtest.cc This function creates a new thread that
and the original thread calls the function SimpleThread The
two threads each execute the loop in the
CPU back and forth five times.
function, in which they yield control of the
Modify the function
becomes:
void
ThreadTestint n;
to take a single integer argument n so that its prototype
Your new version of should fork new threads instead of just one. Test your function
on values of from zero to four. You will have to change the file to supply the required
integer argument to
Next, modify function
to read exactly as follows:
int SharedVariable;
void SimpleThreadint which
int num, val;
fornum ; num ; num
val SharedVariable;
printf thread d sees value d
which, val;
currentThreadYield;
SimpleThread
ThreadTest
main.ccn
nThreadTest
ThreadTest
SimpleThread
#endif#ifdef
void Lo
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
