Home CS439

CS439: Principles of Computer Systems

Discussion Section 3 Problem Set

Due in Section on Friday, February 9, 2023

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. System Calls vs. Procedure Calls: How much more expensive is a system call than a procedure call? Write a simple test program to compare the cost of a simple procedure call to a simple system call ("getuid()" is a good candidate on UNIX; see the man page.) (Note: be careful to prevent the optimizing compiler from "optimizing out" your procedure calls. Do not compile with optimization on.)
    • Explain the difference (if any) between the time required by your simple procedure call and simple system call by discussing what work each call must do (be specific). [Note: Do not provide the source code for your program, just the results].

    Hint: You should use system calls such as gethrtime() or gettimeofday() for time measurements. Design your code such that the measurement overhead is negligible. Also, be aware that timer values in some systems have limited resolution (e.g., millisecond resolution).

  2. 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.

  3. 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.

  4. Compare and contrast monitors and semaphores. What is an appropriate use of each?

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

  6. You need two Hydrogen atoms and one Oxygen atom to make water. Using semaphores, write a pseudocode solution that generates water whenever the right resources are available. You must have three functions: one to generate Oxygen, one to generate Hydrogen, and one to generate water. Assume the three methods may be executed by any number of threads concurrently.
  7. Solve the water problem using monitors (pseudocode).