Homework 2

22C:116, Fall 1998

Due Wednesday Sept 9, 1998, 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/
  1. Why, in the example thread manager, was it necessary to have two distinct functions, thread_manager_init and thread_manager_start?

  2. Inspect the thread data structure thread and the implementation of the thread_relinquish operation, and compare these to the suggested process table fields given in Figure 2-4 of the text and the context switching operation given in Figure 2-5 of the text. Explain the major differences!

  3. Propose a set of data structures that would allow implementation of semaphores under the example thread manager; these should make maximal use of the types already declared in the source code for the thread manager.

  4. Consider the following little UNIX program using parallel processes:
    main()
    {
       int i;
       i = 0;
       if (fork()) {
           int j;
           for (j = 0;j < 1000; j++) { i++; }
           wait();
       } else {
           int j;
           for (j = 0;j < 1000; j++) { i--; }
           exit();
       }
       printf( "%d\n", i );
    }
    
    What output did this program produce? Explain why the output is not zero!