CMSC 412 Midterm #1 (Spring 1998)

 

 

1.)                 (20 points) Deadlock

a)                   What are the four necessary conditions for deadlock?

b)                   Why are these four conditions necessary, but not sufficient?

2.)                  (15 points) Synchronization

a)                   If you computer has an atomic swap instruction, but not test-and-set, show the code to simulate test-and-set using swap.

b)                   In a multi-processor system, why is turning off interrupts on a processor not a sufficient solution to the critical section problem?

3.)                 (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 following properties:

·         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 something else.

Declare variables and semaphores here.  Please indicate initial values.

 

 


Writers execute this code:

 

while (1) {

 

    Write operation;

 

 

}


Readers execute this code:

 

while (1) {

 

    Read operation;

 

}



4.)                 (20 points) Consider the following code from the project, part 2:

void interrupt yield_process ()

{

 

 

  _AX = FP_SEG(dispatch);  /* Push the address of dispatch */

  asm push ax

  _AX =  FP_OFF(dispatch); /* on the top of the  stack */

  asm push ax

 

  runq.stack_top = MK_FP(_SS,_SP);

 

 

}

a)                   Why is the statement runq.stack_top = … needed? We have already set the stack up when we created the process?

b)                   Why is yield_process an interrupt handler?  We only call it from inside system_service which is already an interrupt handler.

5.)                 (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 priority level.

a)                   To penalize compute bound jobs, any jobs that use an entire scheduling quantum are dropped to the next lowest priority level.

 

b)                   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 priority level.

c)                   Any time left in a scheduling quanta when the process voluntarily yields the processor is added to the next scheduling quanta.

Web Accessibility