Homework 3

22C:116, Spring 1999

Due Fri Feb 12, 1998, in class

Douglas W. Jones
  1. Part A: Write a program that runs under the example thread manager. Your program should consist of 5 threads, 3 producers and 2 consumers, connected by a shared FIFO queue of characters. Each producer should produce 10 items and then terminate. The consumers should compute the total number of items dequeued, and the consumer that dequeues the 30th item should output a message before that thread terminates.

    Each thread should call the following function before and after using the shared queue:

    	void may_relinquish()
    	/* call this to randomly do context switching */
    	{
    		if (random() & 3) thread_relinquish();
    	}
    

    Part B: After your program outputs the message saying that the 30th item has been dequeued, the tread manager terminates the entire program; most likely, unless you went to extraordinary effort, the termination is abnormal. If it is abnormal, explain why. If it is not abnormal, explain the extraordinary effort you had to make to make the program terminate normally.

  2. Background Take a look at the description of the fictional MMU for the Hawk machine, found in
    http://homepage.cs.uiowa.edu/~dwjones/arch/hawk/overview.html#mmu
    For this problem, assume that you have high level language routines to read and write the Trap Memory Address Register and the MMU Data Register.

    Part A Give fairly detailed descriptions of the data structures needed for implementing virtual memory on the Hawk machine, focusing on the fields present in the page and frame tables and particularly focusing on the differences between the software data structures and the corresponding structures imposed by the MMU hardware.

    Part B Write high level pseudocode for a page-fault trap service routine on the Hawk machine, assuming that all the low level details like saving and restoring CPU registers are done for you. Focus on the distinction between soft page faults (to update the TLB) and real page faults, and gloss over the actual details of handling real page faults.

  3. A problem Do problem 13 from Chapter 3 in the text!