COSC 125 Operating Systems
Spring 2006
Homework Assignment #6
Preemption and Synchronization
Due: Wednesday, March 29, 1:00PM CST
Submit: E-mail tar-ball (see below) of operating system code to
professor, with a subject header "COSC 125 HW#6, Team ???".
Written answers to the five analysis questions below are due at the
start of class on the due date.
Work may be completed in pairs. Each team should submit only once.
Be certain to put both team member names on work submitted. It would
be courteous to carbon-copy your partner when e-mailing the final
submission.
First, make a fresh copy of your work thus far.
   cp -R xinu-hw5 xinu-hw6
Untar the new project files on top of this directory:
   tar xvzf ~brylow/cosc125/xinu-hw6.tar.gz
You should now see the new project files in with your old files.
Be certain to make clean before compiling for the first time.
The new files
system/irqvec.S,
system/irqret.S,
system/clkintr.c and
system/clkinit.c (as well as some adjustments to various loader
configuration files) will provide you with basic preemption, as discussed
in class. Take time to familiarize yourself with the contents of these
files, as you will be responsible for understanding how these components
of the operating system work.
How can you test that preemption is working in your system? Create a
main program that demonstrates preemptive scheduling.
Call it main-preempt.c, and make sure that it works when copied
over main.c.
Implement classic semaphores with waiting queues. A definition of
the basic semaphore structure is given in include/sem.h, and
is initialized in the new system/initialize.c.
Fill in the functions in
system/newsem.c,
system/signal.c and
system/wait.c. A simple main.c is given that implements
a trivial case of the Producers/Consumers Problem.
Create a main program that spawns multiple producer processes (each
producing a distinctive character output) and multiple consumer processes
(each displaying in a distinctive color).
What happens, and why? Save this testcase as system/main-q1.c.
Using the same testcase as in the previous question, briefly
adjust the value of the preemption counter ("QUANTUM" in
include/kernel.h) to be 100 mS. How does this change the output?
Create a testcase system/main-q3.c in which the consumer
processes are all of a higher priority than the producer processes. Repeat
the first two questions.
In the comment blocks for system/signal.c, you were
directed to reschedule after taking a waiting process off
of the semaphore's wait queue. What happens if you call only ready()
when taking a process off of the wait queue, and do not voluntarily
yield at that time? (This is called non-blocking or non-yielding
signal().) Repeat the first three questions with non-blocking
signal().
One of the interesting things about the classic Producer/Consumer
problem is how finely balanced the solution turns out to be. A
variety of simple one-line swaps in either the producer code or the consumer
code can produce a system of processes that readily deadlocks. Find one
of these combinations, and save it as system/main-q5.c
We now have a basic operating system with preemptive, priority scheduling
of processes, and counting semaphores with wait queues as synchronization
primitives. Explore how the system behaves with various numbers of
producers and consumers at different levels of priority and with both
blocking and non-blocking signals. You will be responsible for making
predictions about how such a system behaves on the next exam.
As an added challenge, you might like to try implementing some of
the other classic synchronization problems outlined in the textbook.
Back