Home CS439

CS439: Principles of Computer Systems

Discussion Section Problem Set 3

Due in Section on Friday, February 9, 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. Given the following piece of code:
    main(int argc, char**argv)
       int child=fork();
       int c=2;
    How many different copies of the variable c are there? What are their values?

  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. Describe the priority inversion problem and give an example situation where it may occur.

  4. Now consider the following program fragment:
    where s1 and s2 are semaphores. All variables are automatic. Now, consider two threads running this fragment of code simultaneously. Can there be a deadlock? Why or why not?

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

  6. Solve the water problem using monitors (pseudocode).