Assignment 5, due Feb. 16
Part of
the homework for CS:3620, Spring 2018
|
On all assignments, your name must be legible as it appears on your University ID card! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions will be by advance arrangement unless there is what lawyers call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the teaching assistant's mailbox. Never push late work under someone's door!
typedef struct { int head, tail, count; /* all initially zero */ char buffer[SIZE]; } queue; void enqueue( queue* q; char ch ) { q->count = q->count + 1; q->buffer[ q->tail ] = ch; q->tail = (q->tail + 1) % SIZE; /* marked */ }
a) Rewrite the marked line so it just increments the tail and then checks to see if it incremented too far and resets the tail to zero. (0.5 points)
b) Suppose SIZE is a power of two. Rewrite the marked line so that it uses the & operator instead of the % (mod) operator. (0.5 points)
a) Assume the code for put() from Figure 9 is used by the user. Identify the point in this code where the interrupt service routine that echoes input keypresses must not interrupt. Note: The code given does not prevent an interrupt at this point; once you identify this point, you will have identified a critical section in the code. (0.5 points)
b) Give appropriate code for the user-level version of put that can be used to protect this critical section. (0.5 points)
On the operating system side, we'd like to think of an array of COM ports, call it comport[], with legal index values from zero to COMPORTS. conceptually, each COM port in this array is an object.
a) Describe the (conceptual, since they're likely to be written in C) methods of each COM port that would be called from the interrupt service routine. Your goal here is to put most of the work into these methods. (0.5 points)
b) Give appropriate code (or object-oriented pseudocode) for the COM interrupt service routine. (0.5 points)