{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

20-Review

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

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

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

View Full Document
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
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)

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

View Full Document
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.

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

View Full Document
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.
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 .

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

View Full Document
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?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern