Assignment 11, due Apr. 20

Part of the homework for 22C:112, Spring 2012
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID and on the class list! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions will be by advance arrangement unless there is what insurance companies call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the instructor's mailbox. Never push late work under someone's door!

  1. Background: The Unix signal() kernel call (now part of the standard library because lower level primitives are available in the kernel) can be used to install a handler. For example, signal(SIGALRM,handler) can be used to set things up so that the function handler() is called when the SIGALRM signal is delivered. Use man  signal and man sigvec for more information.

    The setitimer() kernel call can be used to set the ITIMER_REAL timer. When this timer expires, the SIGALRM signal will be delivered on timer expiration.

    A problem: Write code to install a handler in your program that, once started, will increment the global variable mytimer once per second, doing this independently of all other activity in your program. In effect, you can use the SIGALRM signal and its handler as if they were interrupt service rutines. (1 point)

  2. One approach to exploiting a multicore processor with user-level threads is to begin the parallel application by:

    The number of replica processes should be no more than the number of CPUs or CPU cores available. It may be less if you want to leave some processors to do other things.

    a) Under the above scheme, which of the following are shared (or may be shared) and which are private?

    (0.5 points)

    b) Under the above, if a thread calls, for example, the read() kernel call, and the call blocks, what are the consequences for the other threads? (0.5 points)

  3. Background: Suppose you have a thread package that contains the following primitives, and no others:

    a) How can a user of this thread package implement the semaphore operations wait(s) and signal(s). Your suggested implementation must, of course, suggest a representation for semaphores. (Hint: the answer is almost trivial, no if-statements or loops are required.) (0.5 points)

    b) From the above, can you infer an appropriate implementation of queues that is likely to be used in the implementation of this thread package? Describe, at minimum, the data structure used. (0.5 points)