Memory Barrier - Operating System - Exam, Exams of Operating Systems

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

2012/2013

Uploaded on 03/28/2013

rohit-sharma
rohit-sharma 🇮🇳

4.3

(11)

200 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 15-410: Operating Systems
Mid-Term Exam (C), Fall 2006
1. Please read the entire exam before starting to write. This should help you
avoid getting bogged down on one problem.
2. Be sure to put your name and Andrew ID below and also put your Andrew ID at the top of
each following page.
3. This is a closed-book in-class exam. You may not use any reference materials during the
exam.
4. If you have a clarification question, please write it down on the card we have provided. Please
don’t ask us questions of the form “If I answered like this, would it be ok?” or “Are you
looking for ...?”
5. The weight of each question is indicated on the exam. Weights of question parts are estimates
which may be revised during the grading process and are for your guidance only.
6. Please be concise in your answers. You will receive partial credit for partially correct answers,
but truly extraneous remarks may count against your grade.
7. Write legibly even if you must slow down to do so! If you spend some time to
think clearly about a problem, you will probably have time to write your answer legibly.
Andrew
Username
Full
Name
Question Max Points Grader
1. 15
2. 10
3. 15
4. 15
5. 20
75
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Memory Barrier - Operating System - Exam and more Exams Operating Systems in PDF only on Docsity!

Computer Science 15-410: Operating Systems

Mid-Term Exam (C), Fall 2006

1. Please read the entire exam before starting to write. This should help you

avoid getting bogged down on one problem.

  1. Be sure to put your name and Andrew ID below and also put your Andrew ID at the top of each following page.
  2. This is a closed-book in-class exam. You may not use any reference materials during the exam.
  3. If you have a clarification question, please write it down on the card we have provided. Please don’t ask us questions of the form “If I answered like this, would it be ok?” or “Are you looking for ...?”
  4. The weight of each question is indicated on the exam. Weights of question parts are estimates which may be revised during the grading process and are for your guidance only.
  5. Please be concise in your answers. You will receive partial credit for partially correct answers, but truly extraneous remarks may count against your grade.

7. Write legibly even if you must slow down to do so! If you spend some time to

think clearly about a problem, you will probably have time to write your answer legibly.

Andrew

Username

Full

Name

Question Max Points Grader

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

  1. 10 points Out of Business.

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

  • @param bp Pointer to a biz struct */ workitem * find_work(biz_t *bp) { workitem *w = 0;

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

  • @param bp Pointer to a biz struct */ void go_out_of_business(biz_t *bp) {
  1. 15 points Traveling Traceback.

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.

  1. 15 points Getting grilled.

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

  • burger and consumes one cheesed burger */ void * feeder(void *who) { int want_cheese = complex_function((int) who); int did_cheese = 0; int done = 0; int s;

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.

  1. 20 points Consider the following critical-section protocol:

volatile boolean waiting[2] = { false, false }; volatile int turn = 0;

  1. do {
  2. waiting[i] = true;
  3. if (turn == j) {
  4. while (waiting[j]) {
  5. /* wait with back-off */
  6. waiting[i] = false;
  7. waiting[i] = true;
  8. }
  9. } else {
  10. while (waiting[j]) {
  11. /* wait eagerly */
  12. continue;
  13. }
  14. }
  15. ...critical section...
  16. turn = j;
  17. waiting[i] = false;
  18. ...remainder section...
  19. } while (1);

(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.