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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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
Background 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)
Background image of page 3

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

View Full DocumentRight 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.
Background 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.
Background image of page 5

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

View Full DocumentRight 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.
Background 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 .
Background image of page 7

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

View Full DocumentRight 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? What if the two threads are in different processes?
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/18/2012 for the course INFORMATIK 2011 taught by Professor Phanthuongcang during the Winter '11 term at Cornell.

Page1 / 30

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

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online