Home CS439

CS439: Principles of Computer Systems

Discussion Section Problem Set 3

Due in Section on Friday, September 21, 2018

The problem set must be completed before section and brought to section. To ensure that your problem set is turned in correctly and that you receive credit for discussion section, you must follow these guidelines exactly.

  1. Consider a system using a multilevel feedback queue scheduler. Its scheduler is configured to have four queues, which are, in order of highest priority to lowest priority: Q1, Q2, Q3, and Q4. The queues have quantums sized 5s, 10s, 20s, and 40s, respectively.

    For each of the following three processes, determine which queue it is in when it begins its final quantum.

    • Process A, runtime 40s, blocks every 2s.
    • Process B, runtime 42s, never blocks.
    • Process C, runtime 70s, blocks at 7s, 11s, 25s, 42s, 48s, where those times are points in its execution.

  2. Given the following segment of code:
    char a[100];
    
    thread_func(int r, char ** g)
    {
       int d;
       static double b;
       char * s = "boo";
       char * p;
    
       p = malloc(300);
       return 0;
    }
    
    Identify the memory space in which each variable resides and indicate if the variable is private to a thread or shared amongst threads.

  3. Given the following pseudocode:
    int i = 0;
    
    int main(void)
    { 
       fork();
    
       if(/*CHILD*/)
       {
          i = i - 1;
          return SUCCESS;
       }
       if(/*PARENT*/)
       {
          i = i + 1;
          wait for child to terminate;
    
          printf("i = %d\n", i);
       }
    }
    

    • What is the output? Describe in detail why it is that way.
    • Are there other possible outputs? Why or why not? If so, give another example of what the printed values of ``i'' might be and explain how to force the program to execute the same way each time.

  4. Now consider this pseudocode involving kernel threads:
    int i = 0;
    
    void thread1(void *)
    {
       i = i - 1;
    }
    
    void thread2(void *)
    {
       i = i + 1;
    }
    
    int main(void)
    {
       createThread(thread1);
       createThread(thread2);
    
       /* wait for thread 1 and thread 2 to end */
    
       printf("i = %d\n", i);
    }
    
    • What is the output? Describe in detail why it is that way.
    • Are there other possible outputs? Why or why not? If so, give another example of what the printed values of ``i'' might be and explain how to force the program to execute the same way each time.
  5. Consider a uniprocessor kernel that user programs can trap into using system calls. The kernel receives and handles interrupts from I/O devices. Would there be any need for critical sections within that kernel?

  6. Describe the priority inversion problem and give an example situation where it may occur.