CS 603 Dining Philosopher’s Problem February 15, 2002.

Slides:



Advertisements
Similar presentations
CS 603 Process Synchronization: The Colored Ticket Algorithm February 13, 2002.
Advertisements

CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 14: Deadlock & Dinning Philosophers.
Deadlocks Operating Systems (234123) Spring 2013 Deadlocks Dan Tsafrir (13/5/2013) Partially based on slides by Hagit Attiya OS (234123) - spring 2013.
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Paris, 3 Dec 2007MPRI Course on Concurrency MPRI – Course on Concurrency Lecture 12 Probabilistic process calculi Catuscia Palamidessi LIX, Ecole Polytechnique.
Chapter 6 - Convergence in the Presence of Faults1-1 Chapter 6 Self-Stabilization Self-Stabilization Shlomi Dolev MIT Press, 2000 Shlomi Dolev, All Rights.
CSC321 Concurrent Programming: §3 The Mutual Exclusion Problem 1 Section 3 The Mutual Exclusion Problem.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Approximation, Chance and Networks Lecture Notes BISS 2005, Bertinoro March Alessandro Panconesi University La Sapienza of Rome.
Dining Philosophers (Diners) Problem n definition n Chandy and Misra solution n extension to drinking philosophers.
Announcements. Midterm Open book, open note, closed neighbor No other external sources No portable electronic devices other than medically necessary medical.
© 2004, D. J. Foreman 1 The Dining Philosophers Problem.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
SPL/2010 Liveness And Performance 1. SPL/2010 Performance ● Throughput - How much work can your program complete in a given time unit? ● Example: HTTP.
Page 1 Mutual Exclusion* Distributed Systems *referred to slides by Prof. Paul Krzyzanowski at Rutgers University and Prof. Mary Ellen Weisskopf at University.
Consensus problem Agreement. All processes that decide choose the same value. Termination. All non-faulty processes eventually decide. Validity. The common.
Deadlock CS Introduction to Operating Systems.
Classic Synchronization Problems
Classical Problems of Concurrency
Shared Memory Coordination We will be looking at process coordination using shared memory and busy waiting. –So we don't send messages but read and write.
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
CS603 Process Synchronization February 11, Synchronization: Basics Problem: Shared Resources –Generally data –But could be others Approaches: –Model.
Chapter 7 – Deadlock and Indefinite Postponement
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
CPS110: Deadlock Landon Cox February 5, Concurrency so far  Mostly tried to constrain orderings  Locks, monitors, semaphores  It is possible.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
CS 149: Operating Systems February 17 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Selected topics in distributed computing Shmuel Zaks
Probabilistic Methods in Concurrency Lecture 4 Problems in distributed systems for which only randomized solutions exist Catuscia Palamidessi
Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)
CS151 Complexity Theory Lecture 13 May 11, Outline proof systems interactive proofs and their power Arthur-Merlin games.
Consensus and Its Impossibility in Asynchronous Systems.
10 December 2002ENS Cachan1 Generalized dining philosophers Catuscia Palamidessi, INRIA in collaboration with Mihaela Oltea Herescu, IBM Michael Pilquist,
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 8 Instructor: Haifeng YU.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
Operating Systems (OS)
MPRI – Course on Concurrency Probabilistic methods in Concurrency Catuscia Palamidessi INRIA Futurs and LIX
Physical clock synchronization Question 1. Why is physical clock synchronization important? Question 2. With the price of atomic clocks or GPS coming down,
Hwajung Lee. Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity, non-determinism,
Dining Philosophers A “Classical” Synchronization Problem devised by Edsger Dijkstra in 1965 (modified for the masses by Tony Hoare) You have –5 philosophers.
Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch.
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Deadlock cs550 Operating Systems David Monismith.
Chapter 7 Deadlocks. 7.1 Introduction Deadlock Common approaches to deal with deadlock – Prevention – Avoidance – Detection and recovery.
CS252: Systems Programming Ninghui Li Based on Slides by Prof. Gustavo Rodriguez-Rivera Topic 13: Dinning Philosophers, and Misc.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
1 Fault-Tolerant Consensus. 2 Communication Model Complete graph Synchronous, network.
1 Distributed Vertex Coloring. 2 Vertex Coloring: each vertex is assigned a color.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
Semaphores Chapter 6. Semaphores are a simple, but successful and widely used, construct.
Deadlocks Copyright ©: University of Illinois CS 241 Staff1.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Deadlock CS Introduction to Operating Systems.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Deadlock.
Synchronization Mutual Exclusion Solutions using shared variables + problems such as deadlocks, starvation, progressiveness, busy wait Prof. R K Joshi.
PROBABILITY AND COMPUTING RANDOMIZED ALGORITHMS AND PROBABILISTIC ANALYSIS CHAPTER 1 IWAMA and ITO Lab. M1 Sakaidani Hikaru 1.
Dining Philosophers Five philosophers sit around a table
G.Anuradha Reference: William Stallings
Dining Philosophers (Diners) Problem
Practical Session 12 Deadlocks
CS60002: Distributed Systems
Semaphores Chapter 6.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
CSE 542: Operating Systems
Presentation transcript:

CS 603 Dining Philosopher’s Problem February 15, 2002

Project 2 Starts Today The winner: –NTP Client Basic: Program that accepts NTP server as argument, gets and returns time from that server –Three points for well document and tested solution Extras (worth one additional point): –Fault Tolerant averaging solution: Accepts up to four servers and gives average after throwing away “bad” servers –Class library: Initialize sets offset from local clock, “get time” returns local + offset without sending message

Dining Philosopher’s Problem (Dijkstra ’71)

Dining Philosophers: Solutions Simple: “waiting” state –Enter waiting state when neighbors eating –When neighbors done, get forks –Neighbors can’t enter waiting state if neighbor waiting Problem: –Doesn’t prevent starvation –Requires checking both neighbors at once Race condition

Fully Distributed Solution (Lehman and Rabin ’81) Problem with previous solutions –Not truly distributed: Requires some sort of central coordination or global state –Non-Symmetric: Different philosophers run different algorithms Additional properties: –Deadlock free: Eventually someone new gets to eat –Lockout free: Eventually every hungry philosopher gets to eat –Adversary: One philosopher may try to starve another Can’t just hold the fork indefinitely –Communication only between adjacent philosophers No global state Can’t communicate with both at same time

No Deterministic Solution Proof: Assume solution for philosophers 1..n –P–Philosophers don’t know their number! Philosophers “activated” in order from 1..n –E–Each takes one step Claim: If symmetric at beginning of round, will be symmetric at end of round –I–If anyone eating, all would be!

Probabilistic Solution Assume Random “coin toss” –Guaranteed with probability 1 to break symmetry Idea: Try to get one first –Then get other –If can’t get other, put first down and try again But don’t go for the same fork first every time Think trying = true or die While trying s = random(left,right) Wait for fork s then take it If fork ~s available take it else drop fork s Eat drop s=random(left,right) drop fork ~s

Lemmas: Assume Plato sitting to left of Aristotle 1.If Plato picks up fork infinite number of times, Aristotle finite number, then –P(Plato eats infinite number of times)=1 2.If deadlocked, every philosopher picks up fork infinite number of times with probability 1 3.If after t steps, both trying to eat, tried to get same fork. Then with probability  ½, –One picks up fork only finite number of times in future, or –One gets to eat in next two draws 4.If at time t the last set of random draws is A, then with probability 1 there is a later configuration B ≠ A where two neighbors try to get the same fork first

Theorem: P(Deadlock) = 0 Assume P(Deadlock) > 0 –By Lemma 2, if deadlocked everyone performs infinite draws –By Lemma 4, with probability 1 there will be infinite sequence of configuration of last draws A 0, A 1, … satisfying condition of Lemma 3 –By Lemma 3,  n some philosopher eats between A n and A n+2 with probability 1 Therefore if deadlocked, non-deadlocked condition will occur with probability 1

Problem: Not Lockout-free Courteous Philosophers Possible for all but one to starve Solution: If eating and neighbor trying to eat, once done wait until neighbor has eaten before trying again Requires more shared variables –“signal” to neighbor: On/Off –Share “last” with neighbor: Left, Neutral, Right Initialized to Neutral Only need mutual exclusion with one neighbor at a time Think trying = true; left_signal = right_signal = on s = random(left,right) Wait until s down and (s-neighbor-signal = off or s-last = neutral or s-last = s) then lift fork s If ~s down then lift ~s; trying = false else drop s Eat left-signal = right-signal = off left-last = right; right-last = left Drop forks

Lesson: Non-Determinism Gives Additional Power In fully distributed system, random variable solves problems that can’t otherwise be solved Used in practice –Ethernet: Random backoff if collision Makes proving correctness harder Consider such solutions when building distributed systems!