{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

20-Review - Midterm Review Copyright University of Illinois...

Info icon This preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright ©: University of Illinois CS 241 Staff 1 Midterm Review
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Copyright ©: University of Illinois CS 241 Staff 2 Syllabus Everything up to and including Lecture 18 (deadlock) Main Topics: C, OS, System Calls, Processes, Threads, Scheduling, Synchronization, Classical Synchronization Problems, Deadlock
Image of page 2
Copyright ©: University of Illinois CS 241 Staff Problem 1: Concurrency Thread A for (i=0; i<5; i++) { x = x + 1; } Thread B for (j=0; j<5; j++) { x = x + 2; } Assume A single-processor system Load and store are atomic x is initialized to 0 before either thread starts x must be loaded into a register before being incremented (and stored back to memory afterwards)
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Copyright ©: University of Illinois CS 241 Staff Problem 1: Concurrency Thread A for (i=0; i<5; i++) { x = x + 1; } Thread B for (j=0; j<5; j++) { x = x + 2; } Why is x 15 when both threads have completed? If the x=... statements are not interleaved, x = 15. If they are ever interleaved, this can only cause a smaller or equal value.
Image of page 4
Copyright ©: University of Illinois CS 241 Staff Problem 2: Concurrency Thread A for (i=0; i<5; i++) { x = x + 1; } Thread B for (j=0; j<5; j++) { x = x + 2; } Give a concise proof why x 1 when both threads have completed Every store into x from either Thread A or B is 0, and once x becomes 0, it stays 0. The only way for x =1 is for the last x=x+1 statement in Thread A to load a zero and store a one. However, there are at least four stores from Thread A previous to the load for the last statement, meaning that it couldn’t have loaded a zero.
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Copyright ©: University of Illinois CS 241 Staff Problem 3: Concurrency Thread A for (i=0; i<5; i++) { x = x + 1; } Thread B Suppose we replace ‘ x = x + 2 ’ in Thread B with an atomic double increment operation atomicIncr2(x) that cannot be preempted while being executed. What are all the possible final values of x ? Explain.
Image of page 6
Copyright ©: University of Illinois CS 241 Staff Problem 3: Concurrency Thread A for (i=0; i<5; i++) { x = x + 1; } Thread B for (j=0; j<5; j++) { atomicIncr2(x); } What are all the possible final values of x ? Explain. Final values are 5, 7, 9, 11, 13, or 15. The x=x+2 statements can be “erased” by being between the load and store of an x=x+1 statement. However, since the x=x+2 statements are atomic, the x=x+1 statements can never be “erased” because the load and store phases of x=x+2 cannot be separated. The final value is at least 5 (from Thread A) with from 0 to 5 successful updates of x=x+2 .
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Copyright ©: University of Illinois CS 241 Staff Problem 4: Context Switching What needs to be saved and restored on a context switch between two threads in the same process?
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern