7 Pages

midterm_soln.s03

Course: CSC 453, Fall 2009
School: Cal Poly
Rating:
 
 
 
 
 

Word Count: 2118

Document Preview

453 csc/cpe Midterm Solutions Winter 2003 Name: Section: Key All Rules: Do all your own work. Nothing says your neighbor has any better idea what the answer is. Do not discuss this exam outside of class until after 4:00pm. Suggestions(mostly the obvious): When in doubt, state any assumptions you make in solving a problem. If you think there is a misprint, ask me. Read the questions carefully. Be sure to...

Register Now

Unformatted Document Excerpt

Coursehero >> California >> Cal Poly >> CSC 453

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
453 csc/cpe Midterm Solutions Winter 2003 Name: Section: Key All Rules: Do all your own work. Nothing says your neighbor has any better idea what the answer is. Do not discuss this exam outside of class until after 4:00pm. Suggestions(mostly the obvious): When in doubt, state any assumptions you make in solving a problem. If you think there is a misprint, ask me. Read the questions carefully. Be sure to answer all parts. Identify your answers clearly. Watch the time/point tradeoff: 95ts/50min works out to 31.6s/pt. Problems are not necessarily in order of difficulty. Be sure you have all pages. Pages other than this one are numbered "n of 7". Encouragement: Good Luck! Problem 1 2 3 4 5 6 7 Total: Possible 10 10 10 10 15 20 20 95 1 Score csc/cpe 453 Midterm Solutions Winter 2003 Answer the following questions clearly, concisely, and (where possible) correctly. 1. (10) Busywaiting is often denegrated in the concurrent programming community as a crude and inefficient practice. However, it has its place. (a) First, what is busywaiting? Solution: Busywaiting is the process of repeatedly checking a condition (in a tight loop, e.g.) until it becomes true. (b) Under what circumstances would it be appropriate to choose a busywaiting approach? Solution: It would be appropriate to choose a busywaiting solution: (a) when the expected wait time is small, (b) when there is nothing else to do until the condition is satisfied, or (c) when there is no other mechanism available through which to synchronize. The first and third of these points are often true of synchronizing between processors of a multiprocessor. 2. (10) Semaphore waiting lists are often implemented as queues served in FIFO order. Could they be implemented as stacks? What problems might this cause? Solution: Certainly one could implement semaphore waiting lists as stacks, but doing so would make concurrent processes synchronizing via semaphores much more vulnerable to starvation. 2 of 7 csc/cpe 453 Midterm Solutions Winter 2003 3. (10) What will be the output of the following program? Explain. int main(int argc, char *argv[]){ printf("Hello.\n"); fork(); fork(); fork(); printf("Goodbye!\n"); return 0; } Solution: % a.out Hello. Goodbye! Goodbye! Goodbye! Goodbye! Goodbye! Goodbye! Goodbye! Goodbye! % This program prints "Hello" once in the parent, and "Goodbye!" in each of the 8 resulting processes. There are 7 children created, not 3, because each of the children executes the following fork()s, too. parent c1 parent c2 c1 c3 parent "Goodbye!" c4 "Goodbye!" c2 "Goodbye!" c6 "Goodbye!" c1 "Goodbye!" c5 "Goodbye!" c3 "Goodbye!" c7 "Goodbye!" parent "Hello." 4. (10) A programmer dissatisfied with the behavior of a C library function can redefine it without limiting the capabilities of the program. (That is, there is nothing the program could have done before the redefinition that it could not do afterwards.) A system call, however cannot be replaced without limiting the program. Why is this? Solution: It all has to do with privilege: A system call is the means by which the kernel provides access to a particular operating system service, and the services available through system calls (e.g., reading and writing the disk, allocating memory, starting new processes, etc.) are reserved to the kernel; there is no other way of doing these things. Replacing a system call eliminates that particular entry to the kernel, limiting the program. A library call, in contrast, is code that runs entirely within the user's program requiring only the user's privileges. This code can be replaced by a do-ityourselfer (masochist?) without giving up anything irreplaceable. 3 of 7 csc/cpe 453 Midterm Solutions Winter 2003 5. (15) Given the following program: int main(int argc, char *argv[]){ int n; for(n = 1; n < argc; n++ ) execvp( argv[n], &(argv[n]) ); return 0; } Solution: Suppose that it is compiled in the current directory as myprog and that one gives the command: % myprog myprog ls myprog myprog myprog (a) How many times will execvp() be called during the run of this program? execvp() will be called twice. (b) What will be the expected output of the run? myprog myprog myprog (c) Explain. The program is called with argv containing the list above. Each time around the loop (1...n-1) it will exec() argv[n] with arguments argv[n+1] . . . argv[argc-1]. Because the exec() replaces the current program, the loop never actually loops in any of them. So, the original instance of myprog calls execvp() with "myprog ls myprog myprog myprog" as its arguments. This new instance of myprog will call execvp() with "ls myprog myprog myprog" as its arguments. ls will proceed to list each of its arguments. Since we know myprog is in the current directory, it will be found, so the result of the listing will be "myprog myprog myprog". 4 of 7 csc/cpe 453 Midterm Solutions Winter 2003 6. (20) Assume you have hacked the kernel and are using a version of minix with a 1 second(!) quantum. Suppose there are five user-level jobs, labeled A through E , that require the following amounts of time to run (if they could get the whole CPU to themselves). Job Time A 2 sec. B 3 sec. C 4 sec. D 5 sec. E 2 sec. Supposing that these five jobs become runnable at very close to the same time and are initially added to the run queue in alphabetical order, answer the following questions. Recall that within a priority class, minix uses round-robin scheduling. You may assume that these are the only five jobs in the system and that the overhead required for context switches is negligible. (a) After how many seconds will each job terminate? Briefly explain your reasoning. Solution Time Ending 0.0s 1.0s 2.0s 3.0s 4.0s 5.0s 6.0s 7.0s 8.0s 9.0s 10.0s 11.0s 12.0s 13.0s 14.0s 15.0s 16.0s A -- 1.0s -- -- -- -- 2.0s B -- -- 1.0s -- -- -- -- 2.0s -- -- -- 3.0s C -- -- -- 1.0s -- -- -- -- 2.0s -- -- -- 3.0s -- 4.0s D -- -- -- -- 1.0s -- -- -- -- 2.0s -- -- -- 3.0s -- 4.0s 5.0s E -- -- -- -- -- 1.0s -- -- -- -- 2.0s Job Finish Time A 6 sec. B 11 sec. C 14 sec. D 16 sec. E 10 sec. 5 A A 4 B B B 3 C C C C 2 D D D D D 1 E E 0 0 16 32 48 64 80 96 112 128 144 160 Time (x100.0ms) (b) Now suppose that job D issues an I/O request after each 1.4s it is allowed run. to This I/O request takes 200ms (0.2s) to complete and causes D to block. Now how long will it take for each job to complete? Again, explain your reasoning. Solution 5 A A Job A B C D E Finish Time 6.0 sec. 10.4 sec. 13.4 sec. 16.4 sec. 9.4 sec. Solution: D's first IO is masked by E's execution, but for the second two, there is nothing else to do. Time End 0.0s 1.0s 2.0s 3.0s 4.0s 5.0s 6.0s 7.0s 8.0s 8.4s 9.4s 10.4s 11.4s 12.4s 13.4s 13.8s 14.0s 15.0s 15.4s 15.6s 16.4s A -- 1.0s -- -- -- -- 2.0s B -- -- 1.0s -- -- -- -- 2.0s -- -- -- 3.0s C -- -- -- 1.0s -- -- -- -- 2.0s -- -- -- 3.0s -- 4.0s D -- -- -- -- 1.0s -- -- -- -- 1.4s -- -- -- 2.4s -- 2.8s -- 3.8s 4.2s -- 5.0s E -- -- -- -- -- 1.0s -- -- -- -- 2.0s 4 B B B 3 C C C C 2 D D D D D D D 1 E E 0 IO IO IO 0 16 32 49 65 82 98 114 131 147 163 Time (x100.0ms) 5 of 7 csc/cpe 453 Midterm Solutions Winter 2003 7. (20) Consider the following situation: A very narrow hurricane has washed out all but one lane of the Lake Pontchartrain Causeway1 . Given that it is a very large lake, going around is impractical, so it is necessary to come up with a system to keep the bridge open. The conditions: Cars arrive at random intervals from either the north or south. The remains of the bridge are only one car wide and cars cannot back up. That is, a car that meets another car is stuck forever. Whenever a car wants to enter the bridge, it calls the function enter bridge(int direction) with a pre-defined integer constant indicating the direction. This will be either NORTH or SOUTH. When it wants to leave, it calls exit bridge(int dir). Using semaphores and the C-like syntax used for semaphore examples in class and in Tanenbaum and Woodhull, develop a solution to the problem. Implement enter bridge() and exit bridge() and whatever auxilliary data and functions you may need. Be sure to explain briefly why your solution works. For partial credit: produce a solution that allows cars to cross the bridge without risking meeting another car on the way (and getting stuck forever). For more partial credit: produce a solution that guarantees that no car will have to wait forever to cross. For full credit: produce a solution that does all of the above and allows multiple cars travelling in the same direction to be on the bridge at a time. (It is 24 miles long, after all.) Write your code below (and on page 7 if necessary): Solution: The first two partial credit levels above can be handled by a very simple solution that uses a single semaphore for exclusive access to the bridge. Exclusive access guarantees that there will be no accidents or deadlocks, and the semaphore's own queueing mechanisms guarantee that nobody will have to wait forever. See below. A better solution is presented on page 7. semaphore mutex; /* initialized to 1 */ void enter bridge(direction d) { /* make sure nobody else is on the bridge */ DOWN(mutex); } void exit bridge(direction d) { /* indicate that the bridge is free */ UP(mutex); } A semaphore-based solution to problem 7 that allows one car at a time. 1 Lake Pontchartrain is a lake 41 miles long and 24 miles wide north of New Orleans, La. The causeway is the bridge that spans the "short" direction and is one of the two roads out of the city. 6 of 7 csc/cpe 453 Midterm Solutions Winter 2003 Extra space for problem 7 typedef int direction; #define NORTH 0 #define SOUTH 1 semaphore mutex; semaphore waitsem[2]; /* initialized to 1 */ /* initialized to 0,0 */ The full solution is much trickier: To meet all three requirements, we must not allow traffic in one direction to hold up traffic in the other direction forever, but we can't just take turns, because a car may never arrive on the other side, and we still have to allow multiple cars to cross in the same direction. The technique is to check to s...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Cal Poly - CSC - 454
CPE454 Laboratory Assignment #2 Adding a System CallMichael Haungs, Spring 20091ObjectiveIn this assignment, you will add a new system call, swipe(), to the Linux kernel that transfers the remaining timeslice of each process in a specified se
Cal Poly - CSC - 454
CPE453 Laboratory Assignment #1 Compiling LinuxMichael Haungs, Spring 20091ObjectiveIn this assignment, you will make a small change to the Linux kernel, compile the kernel, and boot to your newly compiled kernel. All work will be done in a v
Cal Poly - CSC - 350
Effective PresentationsCPE 350 Winter 2009 Chris LupoSlides adapted with permission by Lynne Slivovsky and Chris Clark1Oral Presentations &quot;Nothingshould be explained in a way that it cannot be understood by an intelligent 12 year old.&quot; -Alb
Cal Poly - CSC - 350
CPE 350 Winter 2009LupoAssignment 61. Midterm Presentation: Tuesday, March 10, 2009 Working as a team, prepare a 20 minute project presentation. Each team member should speak during the presentation. Use effective strategies to convey content v
Purdue - ECON - 352
Econ 352 Intermediate EconomicsYiLi Chien Spring 2009Homework Assignment 3 Due on April 30th in classQuestion 1 (30 pts): Suppose Jill obeys the two-period model of consumption and earns nothing in the first period and $210 in the second period
Purdue - ECON - 352
Econ 352 Intermediate MacroeconomicsYiLi Chien Spring 2009Practice Final AnswersPart OneInstruction: answer the following questions using analytical frameworks. Depict appropriate diagrams if required.1. (10 pts) In a two period consumption mo
Wells - MATH - 151
Sp'09
Cal Poly - CSC - 471
OutlineGLUT and Event Callbacks Elementary Rendering Points Lines and Polylines Polygons#include &lt;GL/glut.h&gt;A Simple Programvoid display() { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVert
Purdue - ECON - 352
East Los Angeles College - DUB - 12660
PROGRAMME DETAIL SPECIFICATION Programme Summary1 Awarding institution 2 Teaching institution university 3a Programme accredited by: 3b Description of accreditation 4 Final award 5 Programme title 6 UCAS code 7 Subject benchmark statement 8 Educati
Purdue - ECON - 352
Congressional Budget Office Background PaperHousing Wealth and Consumer SpendingJanuary 2007the congress of the united statesPub. No. 2834CBOHousing Wealth and Consumer SpendingJanuary 2007The Congress of the United States O Congressio
Purdue - ECON - 352
Purdue - ECON - 352
Name: _ Date: _ 1. The most volatile component of real GDP is: A) consumption spending. B) government spending. C) investment spending. D) net exports. 2. If the capital stock is fixed and something happens to raise the marginal product of capital (M
Purdue - ECON - 352
annual percentage changeThe LEI index and real GDP, 1990s15 10 5 0 -5 -10 -15 1990199219941996199820002002Leading Economic Indicators Real GDPsource of LEI data: The Conference BoardMistakes forecasting the 1982 recessionUnempl
Purdue - ECON - 352
Name: _ Date: _ 1. Arguments in favor of passive economic policy include all of the following except: A) monetary and fiscal policies work with long and variable lags, which can produce destabilizing results. B) economic forecasts have too large a ma
Purdue - ECON - 352
Name: _ Date: _ 1. The factors most responsible for forecasts of the U.S. government debt spiraling out of control in the next half century are the projected: A) slowdowns in the rates of technological change and human capital growth. B) decrease in
Cal Poly - CSC - 486
Course Overviewx x x x x xIntroduction Interacting with Devices Interaction Styles UI Elements UI Design Guidelines UI Development Toolsx x x xUser Assistance Interaction through Speech Interaction with Mobile Devices Project Presentations 1
Purdue - ECON - 611
ECON 611 Spring 2009 Assignment 4 Answer key 1. An economy consists of two in.nitely lived consumers named i = 1; 2. There is one non-storable consumption good. The endowments to consumer i = 1; 2 are1 yt (st ) = st 2 1 yt (st ) = 1 yt (st )Where
Purdue - ECON - 611
Growth Model with MoneyApril 2, 20091Cash-in-Advance ModelsWe want to consider adding money to the growth model. Let start with simple versionof the model.1.1Model Setting1 X t=0Preferencetu(ct ; 1nt )Resource constraintct =
Purdue - ECON - 611
Note on Asset Pricing and Equity Premium PuzzleApril 30, 200911.1Complete Market with Arrow-Debreu TradingPreference and EndowmentsIn each period there is a realization of an event st :The history of events if denoted st : The conditional pr
Colorado - MCDB - 6440
QUESTION DRIVEN INSTRUCTION: TEACHING SCIENCE (WELL) WITH AN AUDIENCE RESPONSE SYSTEM Ian D. Beatty, William J. Leonard, William J. Gerace, and Robert J. Dufresne Physics Education Research Group Scientific Reasoning Research Institute &amp; Department o
Cal Poly - CSC - 581
=Peer Review Form CSC/CPE 581 &quot;Computer Support for Knowledge Management&quot; Spring 2009Organizers: Franz Kurfess, Cal Poly, USA (fkurfess@csc.calpoly.edu)This is conducted as an &quot;open&quot; review, where the identities of authors and reviewers are re
East Los Angeles College - PHYS - 40521
FPP: BaBar Physics ExamplesSolutions for assessment should be delivered to Roger Barlow by any reasonable means by 5 January 2009, at which time model answers will be put on Teachweb. Example 1 Why does the t quark decay so quickly. Give 3 reasons.
Cal Poly - CSC - 484
UserCentered Design and Development Instructor: Franz J. KurfessComputer Science Dept. Cal Poly San Luis ObispoFJK 2005Copyright Notice These slides are a revised version of the originals provided with the book &quot;Interaction Design&quot; by Jennife
East Los Angeles College - PHYS - 10302
Lecture 10: Waves at Boundaries and Standing Waves1. Wave speed Wave motion can be written in various forms sin(kx - t) cos(kx - t) ei(kx-t) sin(k(x - vt) sin(2(x/ - f t).The speed of the wave is always given by the ratio of whatever multiplies t
East Los Angeles College - PHYS - 10302
Lecture 12: Music1. Audible Frequencies Human hearing spans the range from tens of Hz to a few kHz. The lowest audible frequency is around 16 Hz, and the piano goes down to 27 Hz. The human voice, for an exceptional bass singer, can get to 44 Hz, an
East Los Angeles College - PHYS - 10302
Lecture 20: Interference and Diffraction1. Double (Young's) slits.d d SinConsider a plane wave falling on two slits. The circular wave patterns from the two slits interfere. The key to understanding is to consider the signal that goes in a parti
Cal Poly - CIS - 122
Naval Research LaboratoryWashington, DC 20375-5320UNIX Tools Course NotesInstructor: Michael G. Vonk Center for Computational Science (202)767-3884 michael.vonk@nrl.navy.milUNIX Tools1. 2. Introduction ..1 Bourne Shell Scripts.2 2.1. Shell Sc
East Los Angeles College - LCC - 12671
PROGRAMME DETAIL SPECIFICATION Programme Summary1 Awarding institution 2 Teaching institution university 3a Programme accredited by: 3b Description of accreditation 4 Final award 5 Programme title 6 UCAS code 7 Subject benchmark statement 8 Educati
East Los Angeles College - LSS - 11398
PROGRAMME DETAIL SPECIFICATION Programme Summary1 Awarding institution 2 Teaching institution university 3a Programme accredited by: 3b Description of accreditation 4 Final award 5 Programme title 6 UCAS code 7 Subject benchmark statement 8 Educati
Colorado - HIST - 1010
Lecture 8: The Roman Empire and Its Frontiers Recap: Augustus and the Making of Empire 1. Pax Romana Peace and its Effects A. Stability in an Imperial State B. The Five Good Emperor C. The Spread of Roman Culture 2. Being Roman: A Mediterranean Iden