Sample Midterm Answers
- What are the values of the integer variables x and y when the
following program completes? (If either variable could have more than
one value, say why.)
y = 2;
parbegin
x = y * 2;
y = 6;
parend;
- Is the following true or false? Justify your
answer. "When several processes access shared information in
primary storage, mutual exclusion must be enforced to prevent the
production of indeterminant results."
- Process A should finish before process B starts,
and process B should finish before either of processes C or D start.
Show how these processes may use two semaphores to provide the
necessary synchronization.
- A bounded semaphore s is a counting semaphore that cannot exceed
a given value smax > 0. The corresponding up and
down operations are:
up(s): wait until s < smax; then increment s by 1
down(s): wait until s > 0; then decrement s by 1
Write a monitor to implement bounded semaphores. (Hint: assume the
semaphore is to be initialized to the constant SINIT and the maximum
value is SMAX.)
- Suppose a scheduling algorithm (at the level of
short-term scheduling) favors those programs which have used little
processor time in the recent past. Why will this algorithm favor I/O
bound programs and yet not permanently starve CPU bound programs?
- Assume you have been given the following jobs
with the indicated arrival and service times:
| job name | arrival time | service time |
| A | 0 | 3 |
| B | 2 | 5 |
| C | 4 | 2 |
| D | 6 | 1 |
| E | 8 | 4 |
- When, and in what order, would these jobs run if the scheduling
algorithm were first come first serve?
-
When, and in what order, would these jobs run if the scheduling
algorithm were shortest job next?
-
When, and in what order, would these jobs run if the scheduling
algorithm were round robin with a quantum of 2? Assume that if events
are scheduled to happen at exactly the same time, that new arrivals
precede terminations, which precede quantum expirations.
Send email to
cs150@csif.cs.ucdavis.edu.
Department of Computer Science
University of California at Davis
Davis, CA 95616-8562
Page last modified on 2/2/2000