CSE logo University of Washington Computer Science & Engineering
 CSE 410 Computer Systems - Homework 6 - Spring 2009
  CSE Home   About Us    Search    Contact Info 

Due: Thursday, May 21, at 11 pm.

In this assignment we explore some of the basics of processes and threads.

  1. (Silberschatz 3.7 [8th ed] / 3.2 [7th ed]) Describe the actions taken by a kernel to context-switch between processes.

  2. (Silberschatz 3.13 [8th] / 3.4 [7th], simplified slightly) Given the following program, explain what output will be produced by line A and why. If there is more than one possible output depending on the sequence in which different processes execute, explain what the possible outcomes are and how they could happen.

    (Although this is a C program, the details of the language aren't important. The variable value is a global variable and the function main is the code that makes up the program. A wait(NULL) function call causes a process to pause until its child processes exit. A return inside main terminates the current process. The printf function prints the string "value =" followed by the contents of variable value.)
    int value = 5;
    
    int main {
      pid = fork();
      if (pid == 0) {
        value = value + 15;
        return 0;
      } else {
        wait(NULL);                   /* wait for child process to terminate */
        printf("value = %d", value);  /* LINE A */
        return 0;
      }
     
  3. (Silberschatz 4.1 [8th]) Provide two programming examples in which multithreading provides better performance than a single-threaded solution. (In this and the next question, you don't need to write out detailed code; pseudo-code or a sketch is fine, but be reasonably specific.)

  4. (Silbershatz 4.7 [8th] / 4.1 [7th]) Provide two programming examples in which multithreading does not provide better performance than a single-threaded solution.

  5. (Silberschatz 4.8 [8th] / 4.2 [7th]) Describe the actions taken by a thread library to context switch between user-level threads.

  6. (Silberschatz 4.10 [8th] / 4.4 [7th]) Which of the following components of program state are shared across threads in a multithreaded process?
    1. Register values
    2. Heap memory
    3. Global variables
    4. Stack memory

Turn-in Instructions: Use the turn-in drop box link on the main course web page to submit a file containing your solutions. You can use any common file format, including plain text, word, or pdf. If you wish, you could also scan in a hand-written solution and submit that, but if you do that, please be sure your handwriting is neat and legible. Please be sure to include your name at the top of your answers.


CSE logo Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to Hal Perkins]