Homework 8

22C:116, Spring 2002

Due Monday Apr 15, 2002, in class

Douglas W. Jones

Assume the usual general instructions!

  1. Background Consider a DEMOS-like microkernel, where each process has an array of M mailboxes and an array of L links, where each link is a tuple of the form <p,m>, where p names a process and m names a mailbox of that process. The kernel primitives are:

    make-box(m,i)
    given that the calling process is p, link[i] = <p,m>;
    in effect, link i of process p becomes a reference to mailbox m of process p.

    send(i,buf,len,j,k)
    given <p,m> = link[i],
    sends the message <data(buf,len),link[j],link[k]> to mailbox m of process p;
    in effect, i names the link to send the message, and the message contains the contents of a data buffer and two links.

    receive(m,buf,len,j,k)
    await and receive the message <b,q,r> from mailbox m of the caller;
    store data(buf,len) = b, link[j] = q, link[k] = r

    m = wait_set(s)
    given s is a set of integers in the range 0 to M-1,
    block the caller until, for some m in s, mailbox[m] holds a message.
    in effect, wait until there is at least one waiting message in some box or mailboxes in the set s, and then return the mailbox number of any one non-empty mailbox.
    Our goal is to create a widget server, where the abstract oprations applicable to any widget are twiddle and morph (the nature of a widget and the semantics of these operations are irrelevant). All clients who might wish to create widgets have a link to mailbox zero of the widget server (how they get a link to this mailbox is outside the scope of this question). Messages received in mailbox zero of the server are taken as requests for widget creation; when the server creates a widget, it also associates that widget with one of its mailboxes, and it sends a link connected to that mailbox to the client as part of the reply. Clients use these returned links as handles on widgets, and clients may twiddle or morph those widgets by sending appropriate messages over those links.

    Part A: Outline the code for the widget server. Of course, all details of how it manages widgets will be represented in your code by comments, but you can assume that the server maintains an array of widgets.

    Part B: There are two common implementations of send and receive:

    1. Buffered asynchronous, where the message is saved in a system buffer associated with the receiving mailbox, and the sending process is not blocked, and
    2. Non-buffered synchronous, where the sender is blocked until the receiver opts to receive the message, and then the message is copied directly from the sender's memory to the receiver's memory.
    Does your code from part A work correctly under both of these, or does it depend on the one that is used. If the former, is it possible to build a server that does depend on the model; if the latter, which and why?

  2. Problems from the text:
    Do problems 10 and 16 on page 579 of the text.
    Do problem 20 on page 580.