CS636-2009S-MID

Midterm

March 31, 2009

Name (Last, First):

This exam consists of 5 questions on 9 pages; be sure you have the entire exam before starting. The point value of each question is indicated at its beginning; the entire exam is worth 100 points. Individual parts of a multi-part question are generally assigned approximately the same point value: exceptions are noted. This exam is open text and notes. However, you may NOT share material with another student during the exam. Be concise and clearly indicate your answer. Presentation and simplicity of your answers may affect your grade. Answer each question in the space following the question. If you find it necessary to continue an answer elsewhere, clearly indicate the location of its continuation and label its continuation with the question number and subpart if appropriate. You should read through all the questions first, then pace yourself. The questions begin on the next page. Problem 1 2 3 4 5 Total

Possible 20 20 20 20 20 100

1

Score

CS636-2009S-MID 1. (

Midterm

March 31, 2009

/20 points )

The Process Model The process model is a long standing concept that is fundamental to modern operating systems. In this class we learned about processes in UNIX from the 1974 paper The UNIX Time Sharing System by Ritchie and Thompson. We also know that Android applications run in individual Linux processes. In fact, Google’s new Chrome web browser is designed to run individual browser tabs and plugins in separate processes. Explain why the process model remains pervasive today.

2

CS636-2009S-MID 2. (

Midterm

March 31, 2009

/20 points )

Futexes We spent quite a bit of time in class understanding how futexes work. We looked at the implementation of Pthread mutexes within the Bionic C library for Android. I have provided the source code for normal_lock() and normal_unlock() below. This problem concerns the futex implementation of the semaphore operations: sem_wait() (same as sem_down() or P()) and sem_post() (same as sem_up() or V()). I have provided the implementation of sem_post(), you need to provide an implementation of sem_wait() that works with the sem_post() implementation. /* * Lock a non-recursive mutex. * * As noted above, there are three states: * 0 (unlocked, no contention) * 1 (locked, no contention) * 2 (locked, contention) */ static __inline__ void _normal_lock(pthread_mutex_t* mutex) { /* * The common case is an unlocked mutex, so we begin by trying to * change the lock’s state from 0 to 1. __atomic_cmpxchg() returns 0 * if it made the swap successfully. If the result is nonzero, this * lock is already held by another thread. */ if (__atomic_cmpxchg(0, 1, &mutex->value ) != 0) { /* * We want to go to sleep until the mutex is available, which * requires promoting it to state 2. We need to swap in the new * state value and then wait until somebody wakes us up. * * __atomic_swap() returns the previous value. We swap 2 in and * see if we got zero back; if so, we have acquired the lock. If * not, another thread still holds the lock and we wait again. * * The second argument to the __futex_wait() call is compared * against the current value. If it doesn’t match, __futex_wait() * returns immediately (otherwise, it sleeps for a time specified * by the third argument; 0 means sleep forever). This ensures * that the mutex is in state 2 when we go to sleep on it, which * guarantees a wake-up call. */ while (__atomic_swap(2, &mutex->value ) != 0) __futex_wait(&mutex->value, 2, 0); } }

Problem continued on next page.

3

CS636-2009S-MID

Midterm

/* * Release a non-recursive mutex. The caller is responsible for determining * that we are in fact the owner of this lock. */ static __inline__ void _normal_unlock(pthread_mutex_t* mutex) { /* * The mutex value will be 1 or (rarely) 2. We use an atomic decrement * to release the lock. __atomic_dec() returns the previous value; * if it wasn’t 1 we have to do some additional work. */ if (__atomic_dec(&mutex->value) != 1) { /* * Start by releasing the lock. The decrement changed it from * "contended lock" to "uncontended lock", which means we still * hold it, and anybody who tries to sneak in will push it back * to state 2. * * Once we set it to zero the lock is up for grabs. We follow * this with a __futex_wake() to ensure that one of the waiting * threads has a chance to grab it. * * This doesn’t cause a race with the swap/wait pair in * _normal_lock(), because the __futex_wait() call there will * return immediately if the mutex value isn’t 2. */ mutex->value = 0; /* Wake up one waiting thread. We don’t know which thread will be * woken or when it’ll start executing -- futexes make no guarantees * here. There may not even be a thread waiting. * * The newly-woken thread will replace the 0 we just set above * with 2, which means that when it eventually releases the mutex * it will also call FUTEX_WAKE. This results in one extra wake * call whenever a lock is contended, but lets us avoid forgetting * anyone without requiring us to track the number of sleepers. * * It’s possible for another thread to sneak in and grab the lock * between the zero assignment above and the wake call below. If * the new thread is "slow" and holds the lock for a while, we’ll * wake up a sleeper, which will swap in a 2 and then go back to * sleep since the lock is still held. If the new thread is "fast", * running to completion before we call wake, the thread we * eventually wake will find an unlocked mutex and will execute. * Either way we have correct behavior and nobody is orphaned on * the wait queue. */ __futex_wake(&mutex->value, 1); } }

Problem continued on next page. 4

March 31, 2009

CS636-2009S-MID

typedef struct { volatile unsigned int } sem_t;

Midterm

March 31, 2009

count;

/* * Increment semaphore count and wake up any sleeping threads if necessary */ int sem_post(sem_t *sem) { if (sem == NULL) return EINVAL; if (__atomic_inc((volatile int*)&sem->count) == 0) __futex_wake(&sem->count, 1); return 0; } Put you implementation of sem_wait() in the template below. Provide an English description of your solution. /* * Atomically decrement count. Block thread if count is 0. * Note: do not allow count to go negative, only decrement if positive. */ int sem_wait(sem_t *sem) { if (sem == NULL) { errno = EINVAL; return -1; } /* PUT YOUR CODE HERE */

return 0; } 5

CS636-2009S-MID 3. (

Midterm

March 31, 2009

/20 points )

Mobile Computing and the Cloud Recall the paper Energy-aware adaptation for mobile applications by Flinn and Satyanarayanan. In this paper the authors make the case for having applications adapt to changing power usage requirements. How can emerging cloud computing services work with mobile applications in order to provide better energy efficiency (longer battery life)? Try to be specific and provide as much detail as possible in your answer. That is, more specific and detailed answers will receive higher scores.

6

CS636-2009S-MID 4. (

Midterm

March 31, 2009

/20 points )

Interprocess Communication Systems that use the process model need an efficient way for processes to communicate with each other. What are the problems with using the UNIX pipe mechanism for interprocess communication?

7

CS636-2009S-MID 5. (

Midterm

March 31, 2009

/20 points )

Android Programming Android requires the programmer to save state in response to various events. The idea is that the Android run-time system may choose to terminate a process in memory is running low. Why did Google decide to require the programmer to save and restore state explicitly rather than doing it automatically? Justify your answer.

8

CS636-2009S-MID

Midterm Continue your answers here if necessary.

9

March 31, 2009

CS636-2009S-MID Midterm March 31, 2009 Name

Mar 31, 2009 - Presentation and simplicity of your answers may affect your grade. Answer ... answer elsewhere, clearly indicate the location of its continuation and label its continuation with the question number and .... How can emerging cloud computing services work with mobile applications in order to provide better.

68KB Sizes 4 Downloads 226 Views

Recommend Documents

CS636-2006S-MID Midterm March 23, 2006 Name
This exam is open text and notes. However, you may NOT share material with another student during the exam. Be concise and clearly indicate your answer.

MIDTERM EXAMINATION Spring 2009 MKT624 ... -
Determine the financial contribution gap. ➢ Collect industry data and create a brand vision starter. ➢ Meet with junior management to create .... Which of the following brings management to a platform from where they all have to agree what level

March 2009
Mar 1, 2009 - GHSGT Review /. Pre-Lab. Formal Solubility. Lab. Copper Sulfate + ammonia lab / concentration vs. temperature. Colligative. Properties. 22. 23. 24. 25. 26. 27. 28. Mid term Review. Packet (GHSGT). Mid term Review. Packet (GHSGT). Mid te

March 31, 2013 - Easter Sunday
Mar 31, 2013 - If your email address has changed, please call the office or ..... Automatic Delivery • 24-Hr. Burner Service ... The story of the Good Samaritan.

March 31, 2013 - Easter Sunday
Mar 31, 2013 - Please call the Parish Office to register and obtain information ..... CENTER EYE CARE ... DANIELSHOUSE Licensed Nursing 24 hours a day.

March-2009.pdf
is hard to believe that Allah could smile, Bless. and condone an .... No wonder this. country is in the mess it's in, with half-baked .... March-2009.pdf. March-2009.

Audit Report - 01 August 2008 - 31 March 2009.pdf
Audit Report - 01 August 2008 - 31 March 2009.pdf. Audit Report - 01 August 2008 - 31 March 2009.pdf. Open. Extract. Open with. Sign In. Main menu.

Kylie Thompson ELPS 302 Midterm Exam March 14 ...
Class Collaborative Learning Activity (A). Learning and Investigating Latin American Cultures through Google Slides and. Collaborative Research.

March 31, 2015_Shangri La Catalogue.pdf
Account Name: AACS MARKETING SERVICES. Account Number: 00-253-000471-2. Bank Name: Union Bank of the Philippines. Branch: No.28 Dona Soledad ...

March 31, 2017 MDA.pdf
140 Proof, Inc., (“140 Proof,”) Visible Measures Corp., (Visible Measures) and 2422330 Ontario Inc. All inter-company balances and transactions have been eliminated on consolidation. The information in this report is dated as of May 9, 2017. FORW

BOE March 31, 2003 MeetingMinutes Accounts
They wished everyone up for election good luck. ... Payment #5 to Carroll Seating Company for Trade Package 12a-nw for Science ... 6:310 Credit for Alternative Courses and Programs, and Course Substitutions. 7:50 .... Computer Science AP.

March 31, 2017 MDA.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps. ... March 31, 2017 MDA.pdf. March 31, 2017 MDA.pdf. Open. Extract.

March 2009 SOUTH AFRICAN INSTITUTE OF ELECTRICAL ...
Vol.100(1) March 2009. SOUTH AFRICAN INSTITUTE OF ELECTRICAL ENGINEERS. 2. Page 2. Vol.100(1) March 2009. SOUTH AFRICAN INSTITUTE OF ...

Minutes, March 6, 2009.pdf
Chair: Mike Midgley Location: Room 502, Highland Business Center. Attendees: Mike Midgley, Gary Hampton, David Fonken, Michael Reid, Charles Quinn, Patti Singleton,. Kathleen Christensen, Dan Dydek, Stan Gunn, Suzanne Ortiz, Jon Sack, Don Morris, Haz

DISASTER EXHIBITION; March 03, 2009 - NDMA
Mar 3, 2009 - INVITATION TO DISASTER MANAGEMENT EXHIBITION APRIL. 20-21 ... pamphlets, software etc. and services to the general public. The main ... Payment should be in the form of Cross Cheques/ account only, made out to.

Midterm - GitHub
Feb 21, 2017 - How would your decision to use validation/holdout or k-fold cross validation affect your ability to obtain out-of-sample predictions from the ...

NSE/CML/34529 Date : March 31, 2017 Circular Ref
Mar 31, 2017 - Download Ref.No.: NSE/CML/34529 ... Regulations Part A, it is hereby notified that the list of securities further admitted to dealings on the National ... Divya Poojari. Manager. Telephone No. Fax No. Email id. 022-26598235/36.

NSE/CML/32114 Date : March 31, 2016 Circular Ref
Mar 31, 2016 - Sub : Listing of further issues of DLF Limited, Intellect Design Arena Limited, Monnet. Ispat and ... This circular shall be effective from April 1, 2016. For and on ... Manager. Telephone No. Fax No. Email id. 022-26598459/8346.

[ March 31, 2014 ] [No. 33 s. 2014] DIVISION ORIENTATION ON ...
[ March 31, 2014 ] [No. 33 s. 2014] DIVISION OR ... FORMS AND LEARNER INFORMATION SYSTEM (LIS).pdf. [ March 31, 2014 ] [No. 33 s. 2014] DIVISION ORI .

3rd quarter ended on 31 march 2015.pdf
Page 2 of 5. Statement of Comprehensive Income. Tk' 000. Particulars Note. July 2014. to March 2015. July 2013. to March 2014. January 2015. to March 2015.

Online Registration Instructions 2017-2018 March 31-2017.pdf ...
sign in to your Family Access account. Click on ... Access sites. Page 1 of 5 ... Displaying Online Registration Instructions 2017-2018 March 31-2017.pdf. Page 1 ...

March 31, 2016 Consolidated Financial Statements.pdf
accordance with International Accounting Standard 34, Interim Financial Reporting as. issued by the International Accounting Standards Board and are the ...

NSE/CML/34529 Date : March 31, 2017 Circular Ref
Mar 31, 2017 - This circular shall be effective from April 03, 2017. For and on ... Divya Poojari. Manager. Telephone No. Fax No. Email id. 022-26598235/36.

List of ABMSAROsSub-Allotment Release Orders as of March 31 ...
Page 1 of 1. I u N). oo. E. o. 6', o7o. taogo. 6' o. P@. crIgoJoJodo. q. oea3. O) (,l (r) t9. o. (o. G. {. o (,l. r (, t\. Pdso. tll oooood3. tr. zP iTBBI +E'9EI iiBil. ='s=l B sgl. €. =Il zDml Ift z rl. E. g=l. = ozl. 3 4Cl. E EdI oleol >iol. PPI.