Homework 2

22C:116, Fall 2001

Due Monday Sep 10, 2001, in class

Douglas W. Jones

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list!

  1. Background There is an example thread manager in http://homepage.cs.uiowa.edu/~dwjones/opsys/threads/ This assignment asks about the implementation of process and thread concepts in this package; to prepare, look at the C source code for the package, but do not be dismayed if some parts of this code are very difficult to follow, those parts will not be the subject of the questions here.

    You may need to use the UNIX manual, available from the man command on any UNIX system using the man command. Specifically, you may need look at the man page for setjmp (in part 3 of the manual).

    Part A: Compare the pseudocode for the relinquish operation (or clock interrupt service routine) in the notes for lecture 5 with the implementation of thread_relinquish in the thread package. Certain elements are almost identical to the notes, others are very strange. Explain the function of setjmp and longjmp in this context!

    Part B: Compare the pseudocode for the wait (or P) operation in the notes for lecture 5 with the implementation of thread_wait in the thread package. Aside from the strange use of setjmp and longjmp already noted in part A, what other difference is there between the code and the pseudocode. (hint: Was there an error in the pseudocode?) Explain!

    Part C: The thread_lanuch function in the thread package has some odd parameters that don't relate clearly to anything in the notes. Why do we need to specify the size parameter in a practical implementation of a user-level thread manager, when this corresponds to nothing in our abstract programming model.

  2. Background If a multithreaded application is to be written under the example user-level thread package, we must be very careful about calling system services that might block the entire process -- including all the threads in that process. For example, consider the system service read(), used for all UNIX input! If no data is available on the stream from which a process reads, the process blocks.

    Part A: Explain how the O_NONBLOCK flag can be used (see the documentation for the UNIX fcntl() kernel call) to implement a thread-compatable replacement for read() under the user-level thread manager.

    Part B: Explain how the select() UNIX system call can be used as an alternative approach to implement a thread-compatable replacement for read() under the user-level thread manager.