
















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: Progress, User Mode, Progress, Explanation, One-Paragraph, Clear, Grader, Understand, Applies, Trouble
Typology: Exams
1 / 24
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
After completing 15-410, you and your partner have been hired by a small Pittsburgh fruit-juice distributor to automate their warehouse. Here is how the warehouse operates.
Your partner was hired before you, and deployed the code depicted below. You may assume that all objects are properly initialized before use as part of system start-up.
/* Container loading dock */ mutex_t cd_m; int cd_avail; cond_t cd_released;
/* Delivery loading dock */ mutex_t dd_m; int dd_avail; cond_t dd_released;
/* Forklift --
/* Inventory management */ #define JTYPES 2 // 0=Odwalla, 1=Jamba #define CONTAINER 1000 // cases per truck #define CAPACITY 9000 // total cases per warehouse int avail[JTYPES];
01 void 02 container_arrival(int type) 03 { 04 int ready; 05 06 mutex_lock(&cd_m); 07 ready = 0; 08 while (!ready) { 09 while (!cd_avail) { 10 cond_wait(&cd_released, &cd_m); 11 } 12 cd_avail = 0; // claim 13 14 // Must not overflow warehouse 15 int total = avail[0] + avail[1]; 16 if ((total + CONTAINER > CAPACITY) || 17 (avail[type] + CONTAINER > ((80*CAPACITY)/100))) { 18 // No room, let somebody else try. 19 cd_avail = 1; 20 cond_broadcast(&cd_released); 21 // Retry when space freed up by delivery team 22 cond_wait(&dd_released, &cd_m); 23 } else { 24 ready = 1; 25 } 26 } 27 mutex_unlock(&cd_m); 28 29 // Use forklift to unload 30 mutex_lock(&fl_m); 31 operate_forklift(); 32 avail[type] += CONTAINER; 33 mutex_unlock(&fl_m); 34 35 // Drive away... announce container dock is free 36 mutex_lock(&cd_m); 37 cd_avail = 1; 38 cond_broadcast(&cd_released); 39 mutex_unlock(&cd_m); 40 }
(a) 10 points Something is very wrong with the way this code synchronizes the operation of the warehouse. Clearly explain what is wrong. You should probably provide an exe- cution trace, in the format presented in class, showing the problem in action. Obvious abbreviations are ok. For example: container(0) deliver({10,15}) unlock(cd m); unlock(dd m); If you cannot find a synchronization correctness problem, you may obtain partial credit by describing one “interesting” synchronization correctness problem the code does not have and briefly arguing why your claim is true. Avoid answers of the form “Such-and-such looks wrong, but I’m not sure why,” as these demonstrate understanding of the material poorly at best.
(b) 10 points Provide corrected code for one of the truck-arrival functions. If possible, try to maintain or reduce, rather than increase, the complexity of the system.
You may use this page as extra space for your warehouse solution if you wish.
Different application architectures require different locking approaches. For example, later in the semester we will discuss how real-time scheduling increases the complexity of locking. This question is about a dramatically simpler situation. The application in question has threads of two differ- ent priorities, and some objects must be locked according to a priority-aware protocol. The key requirement is this: when one of these objects is unlocked, it must be acquired by a high-priority thread if any are waiting; otherwise it must be acquired by a low-priority thread if any are waiting.
Each time a thread acquires or releases one of these objects it will indicate whether it is a high- priority thread or a low-priority thread. Threads will not lie and will not change priorities.
You will provide us with both a structure definition for your dual-priority lock and the code for three functions.
You need not provide us with code for dlock destroy(). You are encouraged to use the Project 2 thread-library primitives. If necessary you may use other synchronization primitives, but you should strive to avoid this, as it may reduce your grade. 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.).
Note that you are not required to make the impossible guarantee that no high-priority thread ever waits for a low-priority thread. Furthermore, do not worry if your solution is very slightly imperfect in a way which is not avoidable in certain situations. In other words, the key requirement may be rephrased as follows: when an object is released, if any high-priority threads are waiting, at most one low-priority thread may obtain the object before a high-priority thread does, but the number of low-priority acquisitions in this situation should almost always be zero instead of one.
The remainder of this page is intentionally blank.
(b) 15 points Now please write dlock acquire() and dlock release().
You may use this page as extra space for your dual-priority lock solution if you wish.
This semester, 410 students have formed four rock bands. Each band has a (small) set of songs they have practiced; each song requires an eclectic set of instruments.
Naturally the students are familiar with Professor Dannenberg’s prominence in the field of computer music and figure that instead of buying instruments they can borrow them from him. Roger’s collection contains these instruments. Accordion Bagpipe Cowbell Drum 4 3 2 5
The bands, their songs, and the instruments needed to play each song are listed in the table below. Note that each instrument, each band name, and each song title can be represented unambiguously by a 1-letter or 1-digit abbreviation.
Accordion Bagpipe Cowbell Drum
Band 1: One Thread Yielding Entry of the Threads 1 0 1 1 Free Memory 0 0 1 3
Band 2: Two Cores Groove Gettid 2 0 0 2 Hit The Break Jack 1 1 0 1
Band 3: Three Spare Bits Justify My Yield 0 1 1 1 Kill Dash Nine 3 0 2 2 Lock Free Your Heart 1 3 0 2
Band 4: Forth Mutex Romance 1 1 0 1 Never Going to Halt 2 2 0 4
There was a “battle of the bands” (popularity competition) last weekend, with these four bands and no others.
Because Roger was delayed by bad weather, the 410 students broke into his lab and each band borrowed the instruments necessary to play its first song (E, G, J, and M, respectively). Roger knows that each band is stubborn and will demand to go on stage and be allowed to play all of their songs in some order before being willing to yield the stage or return any instruments to Roger’s collection.
Roger is worried that the naive resource allocations made by the students plus their stubborn policy may have placed the system at risk of deadlock.
(a) 5 points Is there a safe sequence? If so, list a sequence of bands in order. If not, explain why there is not.
You may use this page as extra space for your deadlock solution if you wish.
(c) 5 points Now consider this variant on the protocol of Part B: after every song, each group takes a break (thus releasing all instruments) and then acquires instruments for their next song as described in the Part B protocol. Given all four bands, can this algorithm deadlock? Justify your answer.