











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: Chopsticks, Programs, User Mode, Kernel Mode, Runnable, Progress, Bus Lock, Closed-Book, Class Exam, Reference
Typology: Exams
1 / 19
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.
(a) 5 points Identify and explain one reason for constructing a program so that it uses mul- tiple threads instead of just one thread. We are expecting two to four sentences of answer.
(b) 5 points Identify and explain a second reason for programs to be multi-threaded.
Suppose now that instead of three diners there will be an arbitrary number, D. Furthermore, each diner may require a different number of chopsticks to eat. For example, it is possible that one of the diners is an octopus, who for some reason refuses to begin eating before acquiring eight chopsticks. The second parameter of this scenario is C, the number of chopsticks which would simultaneously satisfy the needs of all diners at the table. For example, Joshua, Caroline, Matt, and one octopus would result in C = 14. Each diner’s eating protocol will be as displayed below.
int s, nsticks = my_chopstick_requirement();
while (!time_to_grade_P2()) { discuss_grading_plan(); for (s = 0; s < nsticks; ++s) acquire_one_chopstick(); /* may block / eat(); for (s = 0; s < nsticks; ++s) release_one_chopstick(); / does not block */ } (b) 8 points What is the smallest number of chopsticks (in terms of D and C) needed to insure that deadlock cannot occur? Explain. Your answer must be organized and con- vincing.
Knowing a theoretical chopstick bound is all well and good, but how will such a system actually work?
You will provide us with code for three functions. Because global variables would restrict us to one table per restaurant, your code will use an alternate formulation involving pointers to table objects.
We will not worry about table destroy(). Your solution can use mutexes and/or condition variables, but may not use semaphores, reader/writer locks, or machine-dependent synchronization instructions. You must comply with the published interfaces of synchronization primitives, i.e., you cannot inspect or modify the internals of any thread-library data objects. You may not use assembly code, inline or otherwise. For the purposes of the exam you should assume an error- free environment (memory allocation will always succeed; thread-library primitives will not detect internal inconsistencies or otherwise “fail,” etc.). You may wish to refer to the “cheat sheets” at the end of the exam.
The remainder of this page is intentionally blank.
(b) 7 points Now please write table acquire one chopstick() and table release one chopstick(), which should, respectively, acquire and release one chopstick at the given table. .
You may use this page as extra space for your table solution if you wish.
23 void unlock() 24 { 25 // figure out who’s next: 26 // active[] set first, starting "to my right" 27 for (k = 1; k < N; k++) { 28 int j = (i + k) % N; 29 if (active[j]) { // j goes next 30 next = j; 31 active[i] = FALSE; 32 locked = FALSE; 33 return; 34 } 35 } 36 // otherwise admit someone from want[] 37 for (k = 1; k < N; k++) { 38 int j = (i + k) % N; 39 if (want[j]) { // j goes next 40 next = j; 41 mygate[j] = TRUE; 42 active[i] = FALSE; 43 mygate[i] = FALSE; 44 locked = FALSE; 45 return; 46 } 47 } 48 // no one is waiting 49 locked = FALSE; 50 gate = TRUE; 51 }
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 and in the homework assignment, as exemplified below. T0 T w[0] = T w[1] = T
Be sure that the execution trace you provide us with is easy to read and conclusively demonstrates the claim you are making. It is very important that you not depict impossible execution sequences! If you wish to claim that some pattern repeats, you must clearly indicate that. Finally, it is strongly recommended that you draft your solution using the scrap paper at the end of the exam before writing anything here.
Use this page as space for the critical-section protocol question.
Consider the following (abbreviated and edited) code from 410kern/boot/head.S, some of the assembly-language underpinnings of the 15-410 kernel base code. Note that start is the entry point to which the boot loader transfers execution; df handler is the start of the double- fault handler; lgdt() and lidt() inform the hardware of the locations of the Global Descrip- tor Table and Interrupt Descriptor Table respectively; and void mb entry(mbinfo t *info, void *istack) is the first C code run in the 410 code base (it is passed a pointer to a structure filled in by the boot loader and a pointer to the stack which is in use). Also, void blat(uint8 t *bytes) is a function, not shown, which fills the screen with many copies of an error message. The message is specified not in standard string format but in a format more convenient for blat().
.global _start, init_gdt, init_idt, init_tss .text init_idt: .space 64 .long 0x .long 0x00108f
init_gdt: .long 0x .long 0x .long 0x2be .long 0x00c08b
init_tss: .space 8 .word 0x .space 94 /* fills with 0’s / df_handler: cli / We got here because we were in trouble, so be conservative / movl $SEGSEL_KERNEL_DS, %eax # AAA movw %ax, %ds # AAA movw %ax, %es # AAA movw %ax, %fs # AAA movw %ax, %gs # AAA movw %ax, %ss # AAA leal istack, %esp # BBB subl $2048, %esp / attempt at preservation / # CCC / Now we probably have a runtime environment */ leal fbytes, %eax pushl %eax call blat df_handler_loop: jmp df_handler_loop
_start: leal istack, %esp /* Load initial stack pointer / movl $init_gdt, %eax subl $init_idt, %eax subl $1, %eax pushl %eax / idt limit == sizeof(idt)-1 / pushl $init_idt call lidt movl $init_tss, %eax subl $init_gdt, %eax subl $1, %eax pushl %eax / gdt limit == sizeof(gdt)-1 / pushl $init_gdt call lgdt addl $16, %esp pushl %esp / Pass in the top of the initial stack / pushl %ebx / Pass in the multiboot structure / call mb_entry / Call the C entry point */ pushl $pbytes call blat stuck: jmp stuck
.data
fbytes: .asciz "D\ro\ru\rb\rl\re\r \rf\ra\ru\rl\rt\r!\r \r"
pbytes: .asciz "K\re\rr\rn\re\rl\r \rc\ra\rn\rn\ro\rt\r \rr\re\rt\ru\rr\rn\r(\r)\r!\r \r"
/* Initial stack */ .space 4096 istack:
A key component of Project 0, the stack crawler, was safely reading values (or not reading values) via pointers which might be invalid. This task can be accomplished by employing several different techniques. Briefly describe two arguments for using the SIGSEGV approach. Then pick one other approach and briefly describe two arguments for using it instead of SIGSEGV.
System-Call Cheat-Sheet
/* Life cycle */ int fork(void); int exec(char *execname, char *argvec[]); void set_status(int status); void vanish(void) NORETURN; int wait(int *status_ptr); void task_vanish(int status) NORETURN;
/* Thread management / int thread_fork(void); / Prototype for exam reference, not for C calling!!! */ int gettid(void); int yield(int pid); int cas2i_runflag(int tid, int oldp, int ev1, int nv1, int ev2, int nv2); int get_ticks(); int sleep(int ticks); / 100 ticks/sec */
/* Memory management */ int new_pages(void * addr, int len); int remove_pages(void * addr);
/* Console I/O */ char getchar(void); int readline(int size, char *buf); int print(int size, char *buf); int set_term_color(int color); int set_cursor_pos(int row, int col); int get_cursor_pos(int *row, int *col);
/* Miscellaneous */ void halt(); int ls(int size, char *buf);
/* "Special" */ void misbehave(int mode);
If you wish, you may tear this page off and use it for scrap paper. But be sure not to write anything on this page which you want us to grade.