Midterm #1 (Spring 1998)
(20 points) Deadlock
What are the four necessary conditions for deadlock?
Why are these four conditions necessary, but not sufficient?
If you computer has an atomic swap instruction, but not
test-and-set, show the code to simulate test-and-set using swap.
In a multi-processor system, why is turning off interrupts on
a processor not a sufficient solution to the critical section problem?
(25 points) You have to solve a variation of the
readers-writers problem, in which multiple writers can write at the same time.
Specifically, there are readers and writers. Up to 5 reads at the same time are
allowed, but only one write at the same time are allowed. A read and a write at
the same time is not allowed. Provide a solution using semaphores with the
no busy waiting.
starvation-free (i.e. a continuous stream of readers does
not starve writers, and vice versa) is desirable but not compulsory (but you will lose some points).
you cannot use process ids and you cannot have a separate
semaphore for every process.
Below is a skeleton program for you to
build upon by supplying code for the boxes and perhaps introducing more
variables. You are also welcome to disregard this skeleton and come up with
variables and semaphores here. Please
indicate initial values.
execute this code:
execute this code:
(20 points) Consider the following code from the project, part
void interrupt yield_process ()
FP_SEG(dispatch); /* Push the address
of dispatch */
_AX = FP_OFF(dispatch); /* on the top of the stack */
runq.stack_top = MK_FP(_SS,_SP);
Why is the statement runq.stack_top
= … needed? We have already set the stack up when we created the
Why is yield_process an
interrupt handler? We only call it from
inside system_service which is already
an interrupt handler.
(20 points) Scheduling.
It has been claimed that for every scheduling strategy, there is a counter strategy
(a way for a user to exploit the policy to their advantage and the detriment of
other users). For each scheduling
policy below, describe a counter strategy. For all cases, assume we are using a
mulit-level feedback queue that does round-robin scheduling within each
To penalize compute bound jobs, any jobs that use an entire
scheduling quantum are dropped to the next lowest priority level.
To help I/O bound jobs, any process that performs an I/O
operation during its scheduling quantum is moved up to the next highest
Any time left in a scheduling quanta when the process voluntarily
yields the processor is added to the next scheduling quanta.