In this assignment you will use the ring simulator to explore process scheduling and synchronization. Read the exercises after Program 4.1 in the text to get a feel for the problem. However, you will just be using the simulator and do not have to compile any programs.
Make a directory called assign3 for all of the files for this assignment.
Part 0
Copy all of the files from
/usr/local/courses/java/ringfiles
into your assign3 directory.
Modify the ringconfig file so the the user line contains
your name instead of Local User. Make sure that
/usr/local/courses/java/bin is in your path and run the ring
simulator using
runring
The simulator should come up and you should be able to create a log file.
Part 1
Open a log file and keep a log of the output generated for each set of runs
described below.
You can display the output generated by the simulated program by clicking on
the Display Info button and then Display Output.
Run the program several times (at least 3)
with the configuration indicated and put the resulting output in the log
file. Push the Reset button between runs. After logging the
output, push the clr button on the output window before starting
the next set of runs.
Try each of the following and record the output generated by the simulated program.
After each of these, change back to the standard configuration:
After fork: parent
Choose Process: FCFS
Scheduling: no preempt
Print Atomic
After running each experiment (which consists of three or more runs with the same parameters) log the output and then clear the output.
After running all of the experiments, answer the following questions:
Part 2
For this part you will run the Tree program. Use the Change Program
button in the second column can choose the TreeOfProcesses program.
This is
similar to the tree of processes of Example 2.7 of PUP. This will be run
with nprocs equal to 5, generating 16 processes.
Make 1 run of the simulator for each of the following:
Use the cover sheet to hand in your assignment. Your log file can be in several parts, but number the pages consecutively and fill in the index on the cover sheet. Then answer the questions on the cover sheet.
Extra Credit (2 points)
Use the simulator to show a mutual exclusion can be done using a single pipe.
Start with the ChainOfProcesses program and insert code before the loop
that creates a ring of one process. Set Print Not Atomic with
probability 0.1 and run the program. Look at the output window. The output
should be garbled.
Now, after the loop, have the first process write a byte to the pipe after it prints its message. All other processes read a byte from the pipe, print the message, and then write a byte to the pipe.
To read and write bytes to the pipe, go into Mode: Program and make a new char variable. Choose New Variable, then char, and then type the name of the variable in the New Char Variable box. Hit ENTER and the box will disappear.
Use the instruction write(1,&var,1) to write one byte to the pipe. You will be prompted for the variable to use. Choose the one you created above.
In a similar way you can use the read(0,&var,1) instruction to read a byte from the pipe.
Create a log file containing your final program and showing the output generated for two programs both with non-atomic print. The first run will be the standard ChainOfProcesses and the second will be your version that uses the pipe for mutual exclusion.