Homework 2

22C:116, Spring 1999

Due Friday Feb 5, 1999, in class

Douglas W. Jones
Several of the problems in this assignment refer to the thread manager given in http://homepage.cs.uiowa.edu/~dwjones/opsys/threads/

Note that large parts of this thread manager are involved with setup of an environment allowing context switching, and that the key parts from the point of view of this assignment come later in the body of the thread package, in the user-callable thread management routines mentioned in the header file, excluding thread_launch(), a body of code that is very difficult to follow. Note also that it is not an error that the header file is not included by the source file!

  1. Part A: Explain the use made of of longjmp() and setjmp() in the function thread_relinquish().

    Part B: Is longjmp() used in the thread manager for exception handling? Where?

  2. Where did all the critical sections go? The code presented in the notes and in lectures was full of "disable interrupts ... critical section ... enable interrupts", but there is nothing analogous in the example thread package!

  3. Consider the following little UNIX program using parallel processes:
    main()
    {
       int i;
       i = 0;
       if (fork()) {
           int j;
           for (j = 0;j < 10; j++) { puts( "x" ); }
           exit();
       } else {
           int j;
           for (j = 0;j < 10; j++) { puts( "y" ); }
           exit();
       }
    }
    
    Translate this program into code to run under the thread manager and explain any differences you observe between the behavior of the original and the behavior of your code running under the thread manager.

  4. Do question 1 on page 141 of Tannenbaum

  5. Do question 4 on page 142 of Tannenbaum