










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Exam of Operating System which includes Caller-Save, Trap Frame, Interrupt Handling, Latest, Processor-Architecture News, Building, Management, Analysis, Management etc.Key important points are: Memory Barrier, Medium Answer, Mode Switch, Grader, Sentence Definition, Understand, Applies, Context Switch, Memory Barrier, Business
Typology: Exams
1 / 18
This page cannot be seen from the preview
Don't miss anything!











think clearly about a problem, you will probably have time to write your answer legibly.
I have not received advance information on the content of this 15-410 mid-term exam by dis- cussing it with anybody who took part in the main exam session or via any other avenue.
Signature: Date
(c) 5 points Memory barrier
Consider the following code:
typedef struct biz { mutex_t m; cond_t new_work; int going_out_of_business; queue q; } biz_t;
/** @brief Return next work item, or NULL if going out of business
mutex_lock(&bp->m);
while(!w && !bp->going_out_of_business) { if (!(w = (workitem *) dequeue(&bp->q))) cond_wait(&bp->new_work, &bp->m); } mutex_unlock(&bp->m); return(w); }
For this question you may assume Project 2 thread library semantics and the existence of an appropriate void enqueue(queue *q, void *item).
(b) 6 points Fill in the contents of go out of business():
/** @brief Shut down this particular business, no matter what
After completing your thread library, you find yourself enamored of the “Pebbles” kernel environ- ment and are eager to port software to it. You realize that one key obstacle stands between you and running your Project 0 traceback() implementation on top of the reference kernel: Pebbles doesn’t have SIGSEGV, msync(), write(), or /proc.
(a) 7 points Briefly explain what you need to accomplish and a way of accomplishing it. Make your explanation clear and convincing. As was the case for Project 0, you are not required to traceback() a program with multiple running threads. Cleaner or more- comprehensive solutions will generally receive more points.
Your student organization takes advantage of one of the last days with good weather to have a grill party. For the purposes of this problem, assume that your organization agrees unanimously on whether or not the burgers to be grilled will be vegetarian. However, some members demand cheese on their burgers, while others reject cheese.
Your task is to codify the procedures to be followed by the event organizer, the chef, and attendees who wish to eat burgers. Your roommate, an ECE major, points out that partygoers are not focused solely on food, taking some time out to socialize, and claims this calls for an an asynchronous, “clock-free” (or “data-flow”) design. This makes sense to you and you churn out the code below. On the “everybody at the party will be a responsible adult” principle, you extend your Project 2 thread library to include thread detach(tid) which (“instantly”) reconfigures a thread so that nobody needs to thr join() it—and, indeed, make it illegal to do so.
extern void talk_to_roommate(int sec), take_a_drink(int sec), admire_scenery(int sec); extern void *chef(void *ignored); extern void *feeder(void *who); extern void light_grill(void); extern int somebody_looks_hungry(void), complex_function(int who), grill_temperature(void);
#define COOKING_TEMP 180 /* degrees / #define COOKING_TIME 45 / seconds */ #define NSLOTS 5 typedef enum { EMPTY, FIRST_SIDE, SECOND_SIDE, READY} slotstate; struct slot { slotstate state; int has_cheese; int since; } grill[NSLOTS];
mutex_t grill_m; cond_t flip; cond_t ready;
/* main() runs "grill party organizer" thread */ int main(void) { int person, tid, s;
thr_init(128*1024); mutex_init(&grill_m); cond_init(&flip); cond_init(&ready);
for (s = 0; s < NSLOTS; s++) { grill[s].state = EMPTY; grill[s].has_cheese = 0; }
light_grill(); while (grill_temperature() <= COOKING_TEMP) sleep(1); thr_create(chef, 0xfeedfeed);
while (grill_temperature() > COOKING_TEMP) { talk_to_roommate(11); /* seconds / while (person = somebody_looks_hungry()) { while ((tid = thr_create(feeder, person)) < 0) talk_to_roommate(3); / seconds / thr_detach(tid); / now no thr_join() is necessary/possible */ } } return (0); }
/* invariant: each cheese-seeker cheeses one
mutex_lock(&grill_m);
while (!done) {
while (want_cheese && !did_cheese) { /* Cheese a burger myself, don’t steal a pre-cheesed one. / / Make sure there’s enough time for cheese to melt. */
cond_wait(&flip, &grill_m);
for (s = 0; s < NSLOTS; s++) { if ((grill[s].state == SECOND_SIDE) && !grill[s].has_cheese && (time(NULL) - grill[s].since < COOKING_TIME/2)) { grill[s].has_cheese = 1; did_cheese = 1; break; } } }
while (!done) { cond_wait(&ready, &grill_m); for (s = 0; s < NSLOTS; s++) { if ((grill[s].state == READY) && (grill[s].has_cheese == want_cheese)) { grill[s].state = EMPTY; /* yum! */ done = 1; break; } } } } mutex_unlock(&grill_m); return (0); }
Unfortunately, at the end of the party, the executive board of your organization meets in secret and votes to strip you of your position and the associated title (“Supreme Grill Coder”).
(a) 5 points Identify and explain why your organization was unhappy with this approach. If you can identify multiple problems, list up to three and indicate their order of seriousness (i.e., “most”, “intermediate”, “least”). Make sure your explanation of each problem is sufficient to provide a genuine diagnosis; no points will be assigned for unsupported claims.
You may use this page as extra space for the grill question if you wish.
volatile boolean waiting[2] = { false, false }; volatile int turn = 0;
(This protocol is presented in “standard form,” i.e., when process 0 is running this code, i == 0 and j == 1; when process 1 is running this code, i == 1 and j == 0, so i means “me” and j means “the other process”) There is a problem with this protocol. That is, it does not ensure that all three requirements (mutual exclusion, progress, and bounded waiting) are always met. Identify a requirement which is not met and lay out a scenario which demonstrates your claim. Use the format presented in class, i.e., P0 P waiting[0] = false; turn = 0; Be sure that the execution trace you provide us with is easy to read and conclusively demon- strates the claim you are making.