Dining Philosophers A “Classical” Synchronization Problem devised by Edsger Dijkstra in 1965 (modified for the masses by Tony Hoare) You have –5 philosophers.

Slides:



Advertisements
Similar presentations
Apoorva Vadi M.S Information Systems New York University
Advertisements

Priority Inversion BAE5030 Advanced Embedded Systems 9/13/04.
Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
Synchronization Methods Topics Mutual-exclusion methods Producer/consumer problem Readers/writers problem CS 105 “Tour of the Black Holes of Computing”
Parallel Programming – Barriers, Locks, and Continued Discussion of Parallel Decomposition David Monismith Jan. 27, 2015 Based upon notes from the LLNL.
Operating Systems Mehdi Naghavi Winter 1385.
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.
Stuff  Exam timetable now available  Class back in CS auditorium as of Wed, June 4 th  Assignment 2, Question 4 clarification.
Deadlock CS Introduction to Operating Systems.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Classic Synchronization Problems
Classical Problems of Concurrency
Avishai Wool lecture Introduction to Systems Programming Lecture 4 Inter-Process / Inter-Thread Communication.
A Introduction to Computing II Lecture 18: Concurrency Issues Fall Session 2000.
Process Synchronization
Chapter 7 – Deadlock and Indefinite Postponement
CS 603 Dining Philosopher’s Problem February 15, 2002.
Computer Science 162 Discussion Section Week 3. Agenda Project 1 released! Locks, Semaphores, and condition variables Producer-consumer – Example (locks,
CSC321 §9 Deadlock 1 Section 9 Deadlock. CSC321 §9 Deadlock 2 Deadlock: four necessary and sufficient conditions  Serially reusable resources: the processes.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Classical problems.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Synchronization II: CPE Operating Systems
Thread Synchronization Tutorial #8 CPSC 261. A thread is a virtual processor Each thread is provided the illusion that it owns a core – Copy of the registers.
1 Chapter 2.3 : Interprocess Communication Process concept  Process concept  Process scheduling  Process scheduling  Interprocess communication Interprocess.
Operating Systems (OS)
Synchronisation Examples
CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
Deadlock cs550 Operating Systems David Monismith.
Verifying Properties of Parallel Programs: An Axiomatic Approach Susan Owicki and David Gries Communications of the ACM, 1976 Presented by Almog Benin.
Semaphores Ref: William Stallings G.Anuradha. Principle of a Semaphore Two or more processes can cooperate by means of simple signals, such that a process.
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.
Review: Monitor Semantics If P does X.wait() and later Q does X.signal(): –Hoare Semantics: Q blocks yielding the monitor immediately to P –Mesa Semantics:
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Synchronization.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Dining Philosophers & Monitors Questions answered in this lecture: How to synchronize dining philosophers? What are monitors and condition variables? What.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Operating System Concepts and Techniques Lecture 16 Deadlock and starvation-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques,
Concurrency (2) CSE 132. Question The following four numbers are in 8-bit 2’s complement form: Which order below represents.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Deadlock CS Introduction to Operating Systems.
Synchronization Deadlocks and prevention
Classical IPC Problems
Dining Philosophers Five philosophers sit around a table
Operating Systems Design (CS 423)
Deadlock Detection & recovery
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Chapter 5: Process Synchronization – Part II
Classical Synchronization Problems
2.4 Classic IPC Problems Dining philosophers Readers and writers
Threads, Concurrency, and Parallelism
Chapter 7 – Deadlock and Indefinite Postponement
Deadlocks (part II) Deadlock avoidance – (not reasonable)
Chapter 5: Process Synchronization (Con’t)
Lecture 15: Dining Philosophers Problem
Applying ... Co631 (Concurrency) Peter Welch
Lecture 25 Syed Mansoor Sarwar
Process Synchronization
Lecture 15: Dining Philosophers Problem
SE350: Operating Systems Lecture 5: Deadlock.
Operating System 6 CONCURRENCY: MUTUAL EXCLUSION AND SYNCHRONIZATION
CENG334 Introduction to Operating Systems
A Holiday Feast!.
Presentation transcript:

Dining Philosophers A “Classical” Synchronization Problem devised by Edsger Dijkstra in 1965 (modified for the masses by Tony Hoare) You have –5 philosophers sitting around a table –Spaghetti on the table –5 forks around the table –Each philosopher needs 2 forks to eat

Dining philosophers (cont) Each philosopher goes in a cycle –Think for a while –Get 2 chopsticks –Eat for a while –Put down the chopsticks –Repeat –Your task is to devise a scheme for the “Get 2 chopsticks” step

Solution 1 (Bad Solution) Think(); Pick up left chopstick; Pick up right chopstick; Eat(); Put down right chopstick; Put down left chopstick; Problem: Deadlock Why? 1. Each philosopher can pick up left fork before anyone picks up their right fork. 2. Now everyone is waiting for right fork.

Solution 2: Global lock Think(); table.lock(); while(!both chopstick available) chopstickPutDown.await(); Pick up left chopstick; Pick up right chopstick; table.unlock(); Eat(); Put down right chopstick; Put down left chopstick; chopstickPutDown.signal();

Solution 3: Reactive Think(); Pick up left chopstick; if(right chopstick available) { Pick up right chopstick; } else { Put down left chopstick; continue; //Go back to Thinking } Eat();

Solution 4: Global ordering Think(); Pick up “smaller” chopstick from left and right; Pick up “bigger” chopstick from left and right; Eat(); Put down “bigger” chopstick from left and right; Put down “smaller” chopstick from left and right; Why can’t we deadlock? 1. It is not possible for all philosophers to have a chopstick 2. Two philosophers, A and B, must share a chopstick, X, that is “smaller” than all other chopsticks 3. One of them, A, has to pick it up X first 4. B can’t pick up X at this point 5. B can’t pick up the bigger one until X is picked up 6. SO, 4 philosophers left, 5 chopsticks total One philosopher must be able to have two chopsticks!