ECE344-Lecture9-Synchronization

ECE344-Lecture9-Synchronization - Lecture 9:...

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

View Full Document Right Arrow Icon
1 Lecture 9: 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 Condition Variables This variable implements a condition : – Threads can sleep on the variable. When the variable changes in value, the threads are woken up. A condition variable (cv) has three operations Wait(cv) • Thread is blocked until a signal. This is typically when some condition is not true. Signal(cv) • Signals that the condition is true and unblocks one thread waiting on the cv. • If a signal occurs before a wait, signal is lost! Broadcast(cv) • Wakes all threads sleeping on the cv
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 Condition Variables Example
Background image of page 4
5 ECE344: Operating Systems Condition Variable Operations Wait, signal and broadcast operations are atomic – Thus, thread must pass a mutex lock whenever they use a cv operation -- avoids lost signal/broadcast race. Usage: – Acquire the lock when you check the condition. If the condition is false, call wait(cv) while holding the lock . – Implementation of wait(cv) atomically releases the lock and sleeps the thread. – Acquire the lock on any operation that can alter the condition. – Another thread also acquires the lock when checking the condition. If the condition is true, it calls signal(cv) while holding the lock.
Background image of page 5

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

View Full DocumentRight Arrow Icon
ECE344: Operating Systems Condition Variable Operations Signaling thread must then release the lock. – Threads woken up from wake(cv) will all reacquire the lock
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

ECE344-Lecture9-Synchronization - Lecture 9:...

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

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