Homework 5

22C:116, Spring 2002

Due Monday Feb 25, 2002, in class

Douglas W. Jones

Assume the usual general instructions!

  1. Background: Look at the user-level thread package found in:
    http://homepage.cs.uiowa.edu/~dwjones/opsys/threads/
    Note! A small update has been made to the package that may allow it to run correctly under MS Visual C and C++. These changes don't relate to this assignment, but if you've been playing with this thread package, they may help.

    Assume we've modified the thread package so that it uses the programmable interval timer to support preemptive context switching between threads.

    Note that the timer sends a signal to the application process that forces premature termination of I/O operations. Before you started using preemptive threads, your code worked correctly with things like write(1,"string\n",7) to output the line "string" to stdout. After you started using preemption, this would occasionally output just "stri" or even "s".

    Part A: Rewrite your application code that said write(1,"string\n",7) to operate correctly under the preemptive thread manager (some relevant material is in the notes for lecture 14, but you'll also find help in the UNIX man page for write).

    Part B: Package your solution to part A in a function, thread_write, that can be substituted for all calls to write in your program.

  2. For each of the following suggested mechanisms for anticipatory paging, suggest the likelyhood that adding it to the virtual memory system would lead to a significant performance improvement:

    a) We could add a system call "anticipate(x)" that the user can use to predict that a use of page x will come soon, and then urge users to include it in their code whenever they can guess future reference patterns of their program.

    b) We could ask the system to attempt to anticipate user reference patterns. For example, when a page fault occurs for page x, the system could check to see if page x+1 is in memory, and if it is not, schedule a read for that page too, since most memory references tend to be sequential.

  3. Problems from the Text: Do problem 32 on page 266 in the text. Do problem 36 on page 267 in the text.