lec7_AdvancedSync

lec7_AdvancedSync - Announcement CSE120 Principles of...

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

View Full Document Right Arrow Icon
1 CSE120 Principles of Operating Systems Prof Yuanyuan (YY) Zhou Lecture 7: Advanced Synchronizations Apr 18th , 2011 Announcement Midterm May 2 nd , lecture time Project 1 due May 2nd 4/18/2011 CSE 120 – Lecture 6 – Semaphores and Monitors 2 4/18/2011 CSE 120 – Lecture 6 – Semaphores and Monitors 3 Semaphore Questions Are there any problems that can be solved with counting semaphores that cannot be solved with mutex semaphores? If a system provides only mutex semaphores, can you use it to implement a counting semaphores? Do it yourself 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 4 Dining Philosophers: an intellectual game Philosophers eat/think Eating needs 2 forks Pick one fork at a time Possible deadlock? How to prevent deadlock?
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 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 5 Does it solve the Dining Philosophers Problem? 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 6 Dining Philosophers Solution 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 7 Dining Philosophers Solution 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 8 The Sleeping Barber Problem N customer Chair One barber can cut one customer’s hair at any time No customer, goes to sleep
Background image of page 2
3 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 9 The Sleeping Barber Solution (1) 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 10 The Sleeping Barber Solution (2) 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 11 The Sleeping Barber Solution (3) Solution to sleeping barber problem. 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 12 Possible Deadlocks with Semaphores Example: P0 P1 share two mutex semaphores S and Q S:= 1; Q:=1; P(S); P(Q); P(Q); P(S); ….. …… V(S); V(Q); V(Q); V(S);
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 4/18/2011 CS 323 - Operating Systems, Yuanyuan Zhou 13 Be Careful When Using Semaphores // Violation of Mutual Exclusion V(mutex); critical section P(mutex); // Deadlock Situation P(mutex); critical section P(mutex); // Violation of Mutual Exclusion critical section V(mutex); 4/18/2011 CSE 120 – Lecture 6 – Semaphores and Monitors 14 Semaphore Summary Semaphores can be used to solve any of the traditional synchronization problems However, they have some drawbacks They are essentially shared global variables Can potentially be accessed anywhere in program No connection between the semaphore and the data being controlled by the semaphore Used both for critical sections (mutual exclusion) and
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

lec7_AdvancedSync - Announcement CSE120 Principles of...

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

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