ECE344-Lecture8-Synchronization

ECE344-Lecture8-Synchronization - Lecture 8:...

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

View Full Document Right Arrow Icon
1 Lecture 8: Synchronization David Lie ECE344 University of Toronto
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 ECE344: Operating Systems Overview Need for synchronization Different synchronization primitives Locks – Conditional Variables – Semaphores Common Synchronization Problems – Deadlocks, Livelock, starvation Tradeoffs with implementing synchronization
Background image of page 2
3 ECE344: Operating Systems Concurrent Programming Programming with two or more cooperating threads Threads can cooperate by Sharing data (shared address space) • Global and heap variables are shared (not locals) Using messages (send and receive using bounded buffer) • Can be implemented using shared variables • Generally, more expensive but more robust
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 ECE344: Operating Systems Concurrent Programming Issues: – There can be requirements on the ordering of operations between the threads: Race Conditions – Two threads T1 and T2 read and update the same variable – Access to the threads must be exclusive (i.e. One at a time) Synchronization – T1 initializes a variable, T2 runs after variable is initialized – Ordering between T1 and T2 must be enforced
Background image of page 4
5 ECE344: Operating Systems Race Conditions A race condition exists in a program when the result of program execution depends on the interleaving of operations between the threads – Definition: A linearizable sequence is a sequence of operations that has the same result if the operations happened atomically. Any sequence that is not linearizable is a race
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 ECE344: Operating Systems Race Condition Bugs Data race: – Two threads performs access on a shared variable simultaneously and at least one performs a write Note that not all race conditions are bugs. Some race conditions can also benign. Examples?
Background image of page 6
7 ECE344: Operating Systems Common Race Conditions Atomicity violation: – 2 or more operations should not be interrupted but another thread operates between them in a non-linearizable way.
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 ECE344: Operating Systems Common Race Conditions Ordering violation: – There is a ordering constraint on operations between two or more threads, but this constraint is violated. Example?
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 document was uploaded on 02/20/2012.

Page1 / 24

ECE344-Lecture8-Synchronization - Lecture 8:...

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