The Drinking Philosophers Problem-1

Size: px
Start display at page:

Download "The Drinking Philosophers Problem-1"

Transcription

1 The Drinking Philosophers Problem The classical Dining Philosophers Problem problem synchronization among competing processes five philosophers (thinking, hungry, and eating) around a table five chopsticks and a bowl of rice when hungry, a philosopher tries to pick up both chopsticks and he/she may pick up only one chopstick at a time when a philosopher gets both chopsticks, he/she eats without releasing his/her chopsticks when a philosopher finishes eating, he/she puts down both chopsticks and starts thinking again solution requirements deadlock-free and starvation-free problem generalization fair conflict resolution in distributed systems Dining Philosophers Problem Drinking Philosophers Problem The Drinking Philosophers Problem-1

2 problem fair conflict resolution in distributed systems conflicts can be resolved only if there is some property by which one P in every set of conflicting P can be distinguished and selected for favorable treatment conflict is resolved in favor of the distinguished P to guarantee fairness, the distinguishing property must be such that the P selected for favorable treatment is not always the same a new approach by using the locations of shared resources as a distinguishing property to fairly resolve all conflicts by introducing auxiliary resources judiciously transferring resources among P ensure two invariants to avoid probabilistic algorithms distinguishability in every state of the system, at least one P in every set of conflicting P must be distinguishable from the other P of the set deadlock-free fairness conflicts should not always be resolved to the detriment of a particular P starvation-free The Drinking Philosophers Problem-2

3 a graph model of conflict a DS is represented by an undirected graph G vertices in G P in the DS edge (u, v) G iff there may be a conflict between u and v assign a precedence ordering to every pair of potentially conflicting P so that one P has precedence over the other G = precedence graph H such that greater precedence P lesser precedence P depth of a processor p in H the max # of edges on any (directed) path to p from a processor without any predecessors a P with no predecessor has depth 0 neighbors cannot have the same depth if H is acyclic, then the depth of a P in H is a distinguishing property by which a P can be distinguished from all P that it may conflict with an algorithm that ensures that H is acyclic in every state of the system guarantee distinguishability but not fairness an algorithm that ensures that every P with conflicts rises to the top (zero depth) in H in finite time system state will change, and hence H will change too The Drinking Philosophers Problem-3

4 how should H change by changing the directions of edges an algorithm to implement H, and changes to H, by using a distributed scheme, where each change in H is made locally at one P H remains acyclic at all times (distinguishability) H changes in such a manner that every conflicting P eventually rises to the top in H (fairness) each change to H be done locally at a P acyclicity rule all edges incident on P may be simultaneously (in one atomic action) redirected toward P ensure acyclicity (distinguishability) fairness rule within finite time after a conflict is resolved in favor of a processor p at depth 0, p must yield precedence to all its neighbors ensure fairness in the event that P at depth 0 is in conflict, it will redirect all incident edges toward itself in finite time summary a distributed implementation of H as well as the acyclicity and fairness rules decide whether to yield or not, in a conflict, based solely on a P s local state The Drinking Philosophers Problem-4

5 The Drinking Philosophers (Drinkers) Problem processors as philosophers are in one of three states tranquil, thirsty, and drinking a bottle (B) is associated with each edge a P can drink only from bottles associated with his incident edges a tranquil P may become thirsty a thirsty P needs a nonempty set of bottles that he wishes to drink from a thirsty P may need different set of bottles for different drinking sessions on holding all needed bottles, a thirsty P starts drinking a thirsty P remains thirsty until he gets all bottles he needs to drink on entering the drinking state, a P remains in that state for a finite period, after which he becomes tranquil a P may be in the tranquil state for an arbitrary period of time The Drinking Philosophers Problem-5

6 devise a nonprobabilistic solution satisfying fairness no P remains thirsty forever (starvation-free) symmetry all P obey precisely the same rules for acquiring and releasing bottles (no priority or any other form of externally specified static partial ordering among P or B) economy a P sends and receives a finite # of msg between state transitions concurrency does not deny the possibility of simultaneous drinking from different B by different P boundedness the # of msg in transit, at any time, between any pair of P is bounded the drinkers problem is a general paradigm for modeling conflicts between P neighboring P will be prevented from drinking simultaneously if they wish to drink from the same B e.g. exclusive write into a common file neighboring P may drink simultaneously from different B e.g. different writes into different files The Drinking Philosophers Problem-6

7 The Dining Philosophers (Diners) Problem the diners problem is a special case of the drinkers problem in which every thirsty P needs B associated with all its incident edges for all drinking sessions the diners problem disallows neighbors from eating simultaneously the drinkers problem allows neighbors to drink simultaneously provided that they are drinking from different B a solution satisfying Fairness, Symmetry, Economy, Concurrency, and Boundness new terms philosophers are in one of three states thinking (tranquil), hungry (thirsty), and eating (drinking) fork (F) bottle (B) The Drinking Philosophers Problem-7

8 An informal solution to the Diners problem a F is either clean or dirty a F being used to eat with is dirty and remains dirty until it is cleaned a clean F remains clean until it is used for eating a P cleans a F when sending it he is hygienic a F is cleaned only when it is sent an eating P does not satisfy requests for F until he has finished eating key issue which requests should a noneating P defer solution a noneating P defers requests for F that are clean and satisfies requests for F that are dirty = implementation of precedence graph H the direction of an edge between two neighbors u and v is from u to v (u has precedence over v) iff u holds the F and F is clean, or v holds the F and F is dirty, or the F is in transit from v to u the direction (from u to v) of the edge can change only when u starts eating all edges incident on an eating P are directed toward him implementation of the acyclicity rule all edges incident on a P may be simultaneously directed toward him (an atomic action) initially all F are dirty and are located at P in such a way that H is acyclic immediately upon completion of an eating session, a P yields precedence to his neighbors The Drinking Philosophers Problem-8

9 A Hygienic Solution to the Diners Problem a request token for each fork Boolean variables for philosopher u fork u (f) philisopher u holds fork f reqf u (f) philisopher u holds the request token for fork f dirty u (f) fork f held by philisopher u is dirty thinking u, hungry u, eating u u is thinking/hungry/eating initial condition all forks are dirty every fork f and request token for f are held by different P H is acyclic a single guarded command (R1 requesting a fork f) hungry, reqf(f), fork(f) send request token for fork f reqf(f) = false (R2 releasing a fork f) eating, reqf(f), dirty(f) send fork f dirty(f) = false fork(f) = false (R3) upon receiving a request for fork f reqf(f) = true (R4) upon receiving fork f fork(f) = true dirty(f) eating fork(f) dirty(f) The Drinking Philosophers Problem-9

10 Proof of Fairness LEMMA 1: H is always acyclic H is acyclic initially observation the direction of edges in H may be affected only when a F changes its status or its location to show that every change to H preserves acyclicity every transmission of a F is accompanied by a change in its status from dirty to clean this does not change the direction of any edge a F is dirtied when the philosopher u holding it, eats (eating fork(f) dirty(f)) u must be holding all F associated with edges incident upon it, and they must all be dirty u cannot then create a cycle in H because all edges upon u are directed toward it The Drinking Philosophers Problem-10

11 THEOREM: Every hungry philosopher eats prove by induction on depth of a hungry philosopher to show that hungry philosophers at depth k in every H eat, provided all hungry philosophers at depth smaller than k in every H eat, k 0 let u, v be neighbors and u be hungry to show that u holds or will hold the f corresponding to the edge (u, v) and will thereafter continue to hold it until u eats if u holds the f currently and holds it continuously until he eats trivial case assume v holds the f sometime before u eats next (Case 1) f is dirty If reqf u (f) holds, then u will request f (rule R1) and subsequently reqf v (f) will hold; otherwise reqf v (f) already holds. If eating v holds, then at some later time (since eating is finite), eating v holds, and all other predicates for rule R2 still hold. Therefore, rule R2 will be applied by v, and u will eventually hold a clean fork. u will not release a clean fork until u eats. (Case 2) f is clean Every F held by a nonhungry philosopher is dirty, because all F are dirty initially only hungry philosophers receive clean F, and all F held by eating philosophers are dirty Since f is clean, the philosopher v holding it must be hungry. Furthermore, because f is clean, (v, u) is an edge in H and hence depth(v) < depth(u). According to the induction hypothesis, v eats and hence dirties f. Case 1 then applies. The Drinking Philosophers Problem-11

12 Drinkers Problem neighboring philosophers may drink simultaneously (from different B) prevent the system from entering states in which neighboring philosophers are indistinguishable A Solution to the Drinkers Problem the solution to the diners problem demonstrates a distributed implementation of the precedence graph H acyclic and fair implement precedence graph H via special auxiliary resources issue due to the distributed implementation of H for neighbors u and v, if u does not hold the fork, we cannot determine which of u and v has precedence from the state of u alone and u must make local decision about holding on to or releasing bottles without using precedence graph H not a problem for Diners need to obtain all forks Idea use forks to implement H forks are auxiliary resources forks are not part of the drinkers problem specification philisophers want B (to drink), not F (to eat) the real resources in the Drinkers problem are bottles forks are part of the solution to the Drinkers problem The Drinking Philosophers Problem-12

13 idea philosopher can eat and drink simultaneously eating is an artifact of the solution to guarantee fair drinking state of a philosopher (diner s state, drinker s state) define dining characteristics of philosopher as part of the solution (D1) Thinking-to-Hungry Transition a thinking, thirsty philosopher becomes hungry (D2) Eating-to-Thinking Transition an eating, non-thirsty philosopher starts thinking hungry-to-eating occurs when a P holds all F (Diners solution) Diners problem: a philosopher can think for arbitrary time although he must eat for finite time (D3) conflict resolution rule ensure eating period is finite u sends a b to v (in response to a request from v) iff [u does not need b] or [u is not drinking and does not hold the fork] u s decision to send or hold onto a bottle depends on whether u holds the fork and does not depend on whether u or v has precedence in H e.g. u must send the b to v if u has precedence over v, but u does not hold the fork example suppose u has precedence over v, but v holds the f u not only requests the b, but also the f via Diners problem, v will yield f to u in finite time after which v will also yield b to u The Drinking Philosophers Problem-13

14 Algorithm for the Drinkers Problem request token (t) Boolean variables bot u (b) u holds bottle b reqb u (b) u holds t for bottle b need u (b) u needs bottle b tranquil u, thirsty u, drinking u initial conditions for Dining philosophers as before for Drinking philosophers b and its t are held by different P state transitions for Dining philosophers (D1) thinking, thirsty hungry = true (D2) eating, thirsty thinking = true other actions of the Dining philosopher remain unchanged rules for b and request token transmissions (R1 requesting a bottle b) thirsty, need(b), reqb(b), bot(b) send request token for bottle b reqb(b) = false (R2 send a bottle b) reqb(b), bot(b), [ need(b) or ( drinking and fork(f)) ] send bottle b bot(b) = false (R3) upon receiving a request for bottle b reqb(b) = true (R4) upon receiving bottle b bot(b) = true The Drinking Philosophers Problem-14

15 Proof of Fairness LEMMA 3: every eating period is finite if u is eating and non-thirsty thinking (stop eating) (D2) if u is eating, it holds all F if u holds a B that it needs, it will not release it until it completes drinking (R2) if u needs and does not hold a B, then it holds the request token it will request the B (R1) v will have to send the B in finite time (R2) = because v does not hold the F and v can be in drinking state only for finite time u will hold all B it needs in finite time since u drinks for finite time, u will become tranquil in finite time u will stop eating in finite time (D2) since every eating period is finite, THEOREM 2 applies = every hungry philosopher eats COROLLARY 4: every hungry philosopher starts eating in finite time THEOREM 5: every thirsty philosopher drinks in finite time when a P becomes thirsty, it is either thinking, hungry, or eating a (thirsty, thinking) P becomes hungry in finite time (D1) a hungry philosopher starts eating in finite time every philosopher who remains thirsty will eat in finite time (LEMMA 3 and D2) = eating can be terminated only by drinking every thirsty philosopher drinks in finite time The Drinking Philosophers Problem-15

Resource Allocation. Pradipta De

Resource Allocation. Pradipta De Resource Allocation Pradipta De pradipta.de@sunykorea.ac.kr Outline Dining Philosophers Problem Drinking Philosophers Problem Dining Philosophers Problem f(5) 5 f(1) Each philosopher goes through, Think

More information

Resource Allocation - Dining Philosophers. Dining Philosophers - Properties. OK? EATING[(i%N)+1]) Impossibility Result for Symmetric Algorithm

Resource Allocation - Dining Philosophers. Dining Philosophers - Properties. OK? EATING[(i%N)+1]) Impossibility Result for Symmetric Algorithm Resource Allocation - Dining Philosophers Dining Philosophers - Properties Five philosophers sit around a circular table. Each philosopher spends his life alternately thinking and eating. In the centre

More information

The Drinking Philosophers Problem: Resource Allocation in Distributed Systems

The Drinking Philosophers Problem: Resource Allocation in Distributed Systems The Drinking Philosophers Problem: Resource Allocation in Distributed Systems Seminar paper on Distributed Programming Alexander Steen, a.steen@fu-berlin.de Freie Universität Berlin Department of Computer

More information

A Modification to the Chandy-Misra Dining Philosophers Algorithm to Support Dynamic Resource Conflict Graphs

A Modification to the Chandy-Misra Dining Philosophers Algorithm to Support Dynamic Resource Conflict Graphs A Modification to the Chandy-Misra Dining Philosophers Algorithm to Support Dynamic Resource Conflict Graphs Kenneth Goldman and Joe Hoffert {kjg,joeh}@cs.wustl.edu Distributed Programing Environments

More information

Introduction to Linear-Time Temporal Logic. CSE 814 Introduction to LTL

Introduction to Linear-Time Temporal Logic. CSE 814 Introduction to LTL Introduction to Linear-Time Temporal Logic CSE 814 Introduction to LTL 1 Outline Motivation for TL in general Types of properties to be expressed in TL Structures on which LTL formulas are evaluated Syntax

More information

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference

More information

Interprocess Communication By: Kaushik Vaghani

Interprocess Communication By: Kaushik Vaghani Interprocess Communication By: Kaushik Vaghani Background Race Condition: A situation where several processes access and manipulate the same data concurrently and the outcome of execution depends on the

More information

Process Management And Synchronization

Process Management And Synchronization Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the

More information

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems

CMSC 330: Organization of Programming Languages. Threads Classic Concurrency Problems : Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks on either

More information

Concurrency pros and cons. Concurrent Programming Problems. Mutual Exclusion. Concurrency is good for users

Concurrency pros and cons. Concurrent Programming Problems. Mutual Exclusion. Concurrency is good for users Concurrency pros and cons Con Programming Problems OS Spring 2009 Concurrency is good for users One of the reasons for multiprogramming Working on the same problem, simultaneous execution of programs,

More information

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition

Chapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Chapter 6: Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages The Dining Philosophers Problem CMSC 0: Organization of Programming Languages Threads Classic Concurrency Problems Philosophers either eat or think They must have two forks to eat Can only use forks on

More information

Concurrency pros and cons. Concurrent Programming Problems. Linked list example. Linked list example. Mutual Exclusion. Concurrency is good for users

Concurrency pros and cons. Concurrent Programming Problems. Linked list example. Linked list example. Mutual Exclusion. Concurrency is good for users Concurrency pros and cons Con Programming Problems OS Spring 2011 Concurrency is good for users One of the reasons for multiprogramming Working on the same problem, simultaneous execution of programs,

More information

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem

CMSC 330: Organization of Programming Languages. The Dining Philosophers Problem CMSC 330: Organization of Programming Languages Threads Classic Concurrency Problems The Dining Philosophers Problem Philosophers either eat or think They must have two forks to eat Can only use forks

More information

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.

Chapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6. Part Three - Process Coordination Chapter 6: Synchronization 6.1 Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure

More information

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock Deadlock in Resource Sharing Environment Operating System Deadlocks CIT 595 Spring 2010 A deadlock occurs when 2 or more processes/threads permanently block each other by each having a lock on a resource

More information

Process Synchronization. studykorner.org

Process Synchronization. studykorner.org Process Synchronization Semaphore Implementation Must guarantee that no two processes can execute wait () and signal () on the same semaphore at the same time The main disadvantage of the semaphore definition

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Chapter 6: Synchronization 6.1 Background 6.2 The Critical-Section Problem 6.3 Peterson s Solution 6.4 Synchronization Hardware 6.5 Mutex Locks 6.6 Semaphores 6.7 Classic

More information

D commercial, industrial, and research establishments. One of

D commercial, industrial, and research establishments. One of IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. 16, NO. 11, NOVEMBER 1990 1293 The Evolving Philosophers Problem: Dynamic Change Management Jeff Kramer and Jeff Magee Abstract-One of the major challenges

More information

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture)

EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) EI 338: Computer Systems Engineering (Operating Systems & Computer Architecture) Dept. of Computer Science & Engineering Chentao Wu wuct@cs.sjtu.edu.cn Download lectures ftp://public.sjtu.edu.cn User:

More information

Process Synchronization

Process Synchronization Process Synchronization Chapter 6 2015 Prof. Amr El-Kadi Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly

More information

3C03 Concurrency: Starvation and Deadlocks

3C03 Concurrency: Starvation and Deadlocks 3C03 Concurrency: Starvation and Deadlocks Wolfgang Emmerich 1 Goals Reader/Writer problem Starvation Dining Philosophers Problem Deadlocks Liveness Analysis using LTS 2 1 Reader / Writer Problem Monitors

More information

The Dining Philosophers with Pthreads

The Dining Philosophers with Pthreads The Dining Philosophers with Pthreads Dr. Douglas Niehaus Michael Jantz Dr. Prasad Kulkarni EECS 678 Dining Philosophers 1 Introduction The Dining Philosophers canonical problem illustrates a number of

More information

Classical Synchronization Problems. Copyright : University of Illinois CS 241 Staff 1

Classical Synchronization Problems. Copyright : University of Illinois CS 241 Staff 1 Classical Synchronization Problems 1 1 This lecture Goals: Topics Introduce classical synchronization problems Producer-Consumer Problem Reader-Writer Problem Dining Philosophers Problem Sleeping Barber

More information

Eventually k-bounded Wait-Free Distributed Daemons

Eventually k-bounded Wait-Free Distributed Daemons Eventually k-bounded Wait-Free Distributed Daemons Yantao Song and Scott M. Pike Texas A&M University Department of Computer Science College Station, TX 77843-3112, USA {yantao, pike}@tamu.edu Technical

More information

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3

Operating Systems Antonio Vivace revision 4 Licensed under GPLv3 Operating Systems Antonio Vivace - 2016 revision 4 Licensed under GPLv3 Process Synchronization Background A cooperating process can share directly a logical address space (code, data) or share data through

More information

The alternator. Mohamed G. Gouda F. Furman Haddix

The alternator. Mohamed G. Gouda F. Furman Haddix Distrib. Comput. (2007) 20:21 28 DOI 10.1007/s00446-007-0033-1 The alternator Mohamed G. Gouda F. Furman Haddix Received: 28 August 1999 / Accepted: 5 July 2000 / Published online: 12 June 2007 Springer-Verlag

More information

Chapter 6: Process Synchronization

Chapter 6: Process Synchronization Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS

More information

Lecture 3: Intro to Concurrent Processing using Semaphores

Lecture 3: Intro to Concurrent Processing using Semaphores Lecture 3: Intro to Concurrent Processing using Semaphores Semaphores; The Prucer-Consumer problem; The Dining Philosophers problem; The Readers-Writers Problem: Readers Preference Passing the Baton Ballhausen

More information

15-440/15-640: Homework 1 Due: September 27, :30am

15-440/15-640: Homework 1 Due: September 27, :30am Name: Andrew ID: 15-440/15-640: Homework 1 Due: September 27, 2016 10:30am 1. Alice wants to send files to Bob over the Internet at the fastest possible speed. To find the best network setting among those

More information

Chapter 7: Process Synchronization!

Chapter 7: Process Synchronization! Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Monitors 7.1 Background Concurrent access to shared

More information

Lesson 6: Process Synchronization

Lesson 6: Process Synchronization Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization

More information

Process Co-ordination OPERATING SYSTEMS

Process Co-ordination OPERATING SYSTEMS OPERATING SYSTEMS Prescribed Text Book Operating System Principles, Seventh Edition By Abraham Silberschatz, Peter Baer Galvin and Greg Gagne 1 PROCESS - CONCEPT Processes executing concurrently in the

More information

Constant RMR Transformation to Augment Reader-Writer Locks with Atomic Upgrade/Downgrade Support

Constant RMR Transformation to Augment Reader-Writer Locks with Atomic Upgrade/Downgrade Support Constant RMR Transformation to Augment Reader-Writer Locks with Atomic Upgrade/Downgrade Support Jake Stern Leichtling Thesis Advisor: Prasad Jayanti With significant contributions from Michael Diamond.

More information

Process Synchronization

Process Synchronization CSC 4103 - Operating Systems Spring 2007 Lecture - VI Process Synchronization Tevfik Koşar Louisiana State University February 6 th, 2007 1 Roadmap Process Synchronization The Critical-Section Problem

More information

OS Process Synchronization!

OS Process Synchronization! OS Process Synchronization! Race Conditions! The Critical Section Problem! Synchronization Hardware! Semaphores! Classical Problems of Synchronization! Synchronization HW Assignment! 3.1! Concurrent Access

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 1018 L11 Synchronization Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel feedback queue:

More information

5 Classical IPC Problems

5 Classical IPC Problems OPERATING SYSTEMS CLASSICAL IPC PROBLEMS 2 5 Classical IPC Problems The operating systems literature is full of interesting problems that have been widely discussed and analyzed using a variety of synchronization

More information

Object Oriented Programming and Design in Java. Session 18 Instructor: Bert Huang

Object Oriented Programming and Design in Java. Session 18 Instructor: Bert Huang Object Oriented Programming and Design in Java Session 18 Instructor: Bert Huang Announcements Homework 4 due Mon. Apr. 19 No multithreading in programming part Final Exam Monday May 10, 9 AM - noon, 173

More information

Petri Nets ~------~ R-ES-O---N-A-N-C-E-I--se-p-te-m--be-r Applications.

Petri Nets ~------~ R-ES-O---N-A-N-C-E-I--se-p-te-m--be-r Applications. Petri Nets 2. Applications Y Narahari Y Narahari is currently an Associate Professor of Computer Science and Automation at the Indian Institute of Science, Bangalore. His research interests are broadly

More information

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems

Synchronization. CS 475, Spring 2018 Concurrent & Distributed Systems Synchronization CS 475, Spring 2018 Concurrent & Distributed Systems Review: Threads: Memory View code heap data files code heap data files stack stack stack stack m1 m1 a1 b1 m2 m2 a2 b2 m3 m3 a3 m4 m4

More information

CS370 Operating Systems

CS370 Operating Systems CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 12 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ 2 Mutex vs Semaphore Mutex is binary,

More information

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; }

Semaphore. Originally called P() and V() wait (S) { while S <= 0 ; // no-op S--; } signal (S) { S++; } Semaphore Semaphore S integer variable Two standard operations modify S: wait() and signal() Originally called P() and V() Can only be accessed via two indivisible (atomic) operations wait (S) { while

More information

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Class Notes, 3/21/07, Operating Systems

Class Notes, 3/21/07, Operating Systems Class Notes, 3/21/07, Operating Systems Hi, Jane. Thanks again for covering the class. One of the main techniques the students need to how to recognize when there is a cycle in a directed graph. (Not all

More information

Mutual Exclusion. 1 Formal problem definitions. Time notion CSE /17/2015. Outline of this lecture:

Mutual Exclusion. 1 Formal problem definitions. Time notion CSE /17/2015. Outline of this lecture: CSE 539 03/17/2015 Mutual Exclusion Lecture 15 Scribe: Son Dinh Outline of this lecture: 1. Formal problem definitions 2. Solution for 2 threads 3. Solution for n threads 4. Inherent costs of mutual exclusion

More information

A DAG-BASED ALGORITHM FOR DISTRIBUTED MUTUAL EXCLUSION ATHESIS MASTER OF SCIENCE

A DAG-BASED ALGORITHM FOR DISTRIBUTED MUTUAL EXCLUSION ATHESIS MASTER OF SCIENCE A DAG-BASED ALGORITHM FOR DISTRIBUTED MUTUAL EXCLUSION by Mitchell L. Neilsen ATHESIS submitted in partial fulfillment of the requirements for the degree MASTER OF SCIENCE Department of Computing and Information

More information

CSE 4/521 Introduction to Operating Systems

CSE 4/521 Introduction to Operating Systems CSE 4/521 Introduction to Operating Systems Lecture 7 Process Synchronization II (Classic Problems of Synchronization, Synchronization Examples) Summer 2018 Overview Objective: 1. To examine several classical

More information

Concurrency: Deadlock and Starvation. Chapter 6

Concurrency: Deadlock and Starvation. Chapter 6 Concurrency: Deadlock and Starvation Chapter 6 Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involve conflicting needs for resources

More information

Self Stabilization. CS553 Distributed Algorithms Prof. Ajay Kshemkalyani. by Islam Ismailov & Mohamed M. Ali

Self Stabilization. CS553 Distributed Algorithms Prof. Ajay Kshemkalyani. by Islam Ismailov & Mohamed M. Ali Self Stabilization CS553 Distributed Algorithms Prof. Ajay Kshemkalyani by Islam Ismailov & Mohamed M. Ali Introduction There is a possibility for a distributed system to go into an illegitimate state,

More information

Deadlock CS 241. March 19, University of Illinois

Deadlock CS 241. March 19, University of Illinois Deadlock CS 241 March 19, 2014 University of Illinois Slides adapted in part from material accompanying Bryant & O Hallaron, Computer Systems: A Programmer's Perspective, 2/E 1 The Dining Philosophers

More information

Synchronization problems with semaphores

Synchronization problems with semaphores Synchronization problems with semaphores Lecture 4 of TDA384/DIT391 (Principles of Concurrent Programming) Carlo A. Furia Chalmers University of Technology University of Gothenburg SP3 2017/2018 Today

More information

Distributed Algorithms 6.046J, Spring, Nancy Lynch

Distributed Algorithms 6.046J, Spring, Nancy Lynch Distributed Algorithms 6.046J, Spring, 205 Nancy Lynch What are Distributed Algorithms? Algorithms that run on networked processors, or on multiprocessors that share memory. They solve many kinds of problems:

More information

Liveness properties. Deadlock

Liveness properties. Deadlock Liveness properties From a theoretical viewpoint we must ensure that we eventually make progress i.e. we want to avoid : blocked threads/processes waiting for each other Livelock: processes/threads execute

More information

MPRI Course on Concurrency. Lecture 16. The need for randomization: examples in distributed computing and in security

MPRI Course on Concurrency. Lecture 16. The need for randomization: examples in distributed computing and in security MPRI Course on Concurrency Lecture 16 The need for randomization: examples in distributed computing and in security Kostas Chatzikokolakis LIX, Ecole Polytechnique kostas@lix.polytechnique.fr www.lix.polytechnique.fr/~kostas

More information

Dining Philosophers, Semaphores

Dining Philosophers, Semaphores CS 220: Introduction to Parallel Computing Dining Philosophers, Semaphores Lecture 27 Today s Schedule Dining Philosophers Semaphores Barriers Thread Safety 4/30/18 CS 220: Parallel Computing 2 Today s

More information

Deadlock. Concepts: Models: Practice: Aim: deadlock avoidance - to design systems where deadlock cannot occur. Chapter 6. Deadlock

Deadlock. Concepts: Models: Practice: Aim: deadlock avoidance - to design systems where deadlock cannot occur. Chapter 6. Deadlock Chapter 6 Deadlock Deadlock Concepts: Models: Practice: system deadlock: no further progress four necessary & sufficient conditions deadlock - no eligible actions blocked threads Aim: deadlock avoidance

More information

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION Copyright Cengage Learning. All rights reserved. SECTION 5.5 Application: Correctness of Algorithms Copyright Cengage Learning. All rights reserved.

More information

CHAPTER 6: PROCESS SYNCHRONIZATION

CHAPTER 6: PROCESS SYNCHRONIZATION CHAPTER 6: PROCESS SYNCHRONIZATION The slides do not contain all the information and cannot be treated as a study material for Operating System. Please refer the text book for exams. TOPICS Background

More information

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1

Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1 CME 305: Discrete Mathematics and Algorithms Instructor: Professor Aaron Sidford (sidford@stanford.edu) January 11, 2018 Lecture 2 - Graph Theory Fundamentals - Reachability and Exploration 1 In this lecture

More information

System Software. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 13

System Software. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 13 System Software Computer Science and Engineering College of Engineering The Ohio State University Lecture 13 Road Map Lectures Administration Abstract machine characteristics Version control Software engineering

More information

Lecture 27: Safety and Liveness Properties, Java Synchronizers, Dining Philosophers Problem

Lecture 27: Safety and Liveness Properties, Java Synchronizers, Dining Philosophers Problem COMP 322: Fundamentals of Parallel Programming Lecture 27: Safety and Liveness Properties, Java Synchronizers, Dining Philosophers Problem Mack Joyner and Zoran Budimlić {mjoyner, zoran}@rice.edu http://comp322.rice.edu

More information

Deadlock Wednesday, October 13, :08 PM

Deadlock Wednesday, October 13, :08 PM Deadlock Page 1 Deadlock Wednesday, October 13, 2004 8:08 PM Deadlock Other side of spectrum (from race conditions) Common forms Circular dependencies. Resource saturation. All symptoms of roughly the

More information

These notes present some properties of chordal graphs, a set of undirected graphs that are important for undirected graphical models.

These notes present some properties of chordal graphs, a set of undirected graphs that are important for undirected graphical models. Undirected Graphical Models: Chordal Graphs, Decomposable Graphs, Junction Trees, and Factorizations Peter Bartlett. October 2003. These notes present some properties of chordal graphs, a set of undirected

More information

EECS 482 Introduction to Operating Systems

EECS 482 Introduction to Operating Systems EECS 482 Introduction to Operating Systems Winter 2018 Baris Kasikci Slides by: Harsha V. Madhyastha Recap How to leverage hardware support to implement high-level synchronization primitives? Lock implementation

More information

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University Frequently asked questions from the previous class survey CS 370: SYSTEM ARCHITECTURE & SOFTWARE [PROCESS SYNCHRONIZATION] Shrideep Pallickara Computer Science Colorado State University Semaphores From

More information

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28) Lecture Topics Today: Concurrency (Stallings, chapter 5.1-5.4, 5.7) Next: Exam #1 1 Announcements Self-Study Exercise #5 Project #3 (due 9/28) Project #4 (due 10/12) 2 Exam #1 Tuesday, 10/3 during lecture

More information

Last Class: Synchronization Problems!

Last Class: Synchronization Problems! Last Class: Synchronization Problems! Reader Writer Multiple readers, single writer In practice, use read-write locks Dining Philosophers Need to hold multiple resources to perform task Lecture 11, page

More information

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G. MAD 3105 Spring 2006 Solutions for Review for Test 2 1. Define a graph G with V (G) = {a, b, c, d, e}, E(G) = {r, s, t, u, v, w, x, y, z} and γ, the function defining the edges, is given by the table ɛ

More information

Synchronization Principles II

Synchronization Principles II CSC 256/456: Operating Systems Synchronization Principles II John Criswell University of Rochester 1 Synchronization Issues Race conditions and the need for synchronization Critical Section Problem Mutual

More information

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - XI Deadlocks - II. Louisiana State University

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - XI Deadlocks - II. Louisiana State University CSC 4103 - Operating Systems Fall 2009 Lecture - XI Deadlocks - II Tevfik Ko!ar Louisiana State University September 29 th, 2009 1 Roadmap Classic Problems of Synchronization Bounded Buffer Readers-Writers

More information

Roadmap. Bounded-Buffer Problem. Classical Problems of Synchronization. Bounded Buffer 1 Semaphore Soln. Bounded Buffer 1 Semaphore Soln. Tevfik Ko!

Roadmap. Bounded-Buffer Problem. Classical Problems of Synchronization. Bounded Buffer 1 Semaphore Soln. Bounded Buffer 1 Semaphore Soln. Tevfik Ko! CSC 4103 - Operating Systems Fall 2009 Lecture - XI Deadlocks - II Roadmap Classic Problems of Synchronization Bounded Buffer Readers-Writers Dining Philosophers Sleeping Barber Deadlock Prevention Tevfik

More information

Single Source Shortest Path

Single Source Shortest Path Single Source Shortest Path A directed graph G = (V, E) and a pair of nodes s, d is given. The edges have a real-valued weight W i. This time we are looking for the weight and the shortest path from s

More information

Process Synchronization

Process Synchronization TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Process Synchronization [SGG7] Chapter 6 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin

More information

Process Synchronization

Process Synchronization Process Synchronization Concurrent access to shared data in the data section of a multi-thread process, in the shared memory of multiple processes, or in a shared file Although every example in this chapter

More information

Roadmap. Readers-Writers Problem. Readers-Writers Problem. Readers-Writers Problem (Cont.) Dining Philosophers Problem.

Roadmap. Readers-Writers Problem. Readers-Writers Problem. Readers-Writers Problem (Cont.) Dining Philosophers Problem. CSE 421/521 - Operating Systems Fall 2011 Lecture - X Process Synchronization & Deadlocks Roadmap Classic Problems of Synchronization Readers and Writers Problem Dining-Philosophers Problem Sleeping Barber

More information

Chapter 6 Concurrency: Deadlock and Starvation

Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles Chapter 6 Concurrency: Deadlock and Starvation Seventh Edition By William Stallings Edited by Rana Forsati CSE410 Outline Principles of deadlock Deadlock

More information

Deadlocks. Copyright : University of Illinois CS 241 Staff 1

Deadlocks. Copyright : University of Illinois CS 241 Staff 1 Deadlocks 1 Deadlock Which way should I go? 2 Deadlock I Oh can no! almost I m get stuck! across GRIDLOCK! 3 Deadlock Definition Deadlocked process Waiting for an event that will never occur Typically,

More information

Concurrency: Deadlock and Starvation. Chapter 6

Concurrency: Deadlock and Starvation. Chapter 6 Concurrency: Deadlock and Starvation Chapter 6 1 What is Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate with each other Involve conflicting needs

More information

Dealing with Issues for Interprocess Communication

Dealing with Issues for Interprocess Communication Dealing with Issues for Interprocess Communication Ref Section 2.3 Tanenbaum 7.1 Overview Processes frequently need to communicate with other processes. In a shell pipe the o/p of one process is passed

More information

Greedy Algorithms 1 {K(S) K(S) C} For large values of d, brute force search is not feasible because there are 2 d {1,..., d}.

Greedy Algorithms 1 {K(S) K(S) C} For large values of d, brute force search is not feasible because there are 2 d {1,..., d}. Greedy Algorithms 1 Simple Knapsack Problem Greedy Algorithms form an important class of algorithmic techniques. We illustrate the idea by applying it to a simplified version of the Knapsack Problem. Informally,

More information

Concurrency: Deadlock 1. Magee/Kramer 2 nd Edition

Concurrency: Deadlock 1. Magee/Kramer 2 nd Edition Concurrency: Deadlock 1 Concurrency: Deadlock 2 Chapter 6 Deadlock Concurrency: Deadlock 3 Deadlock Concepts: system deadlock: no further progress four necessary & sufficient conditions Models: deadlock

More information

Module 6: Process Synchronization

Module 6: Process Synchronization Module 6: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris

More information

Process Synchronization

Process Synchronization Process Synchronization Part II, Modified by M.Rebaudengo - 2013 Silberschatz, Galvin and Gagne 2009 Classical Problems of Synchronization Consumer/Producer with Bounded-Buffer Problem s and s Problem

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - XXVI April 27 th, 2006 1 Roadmap Shared Memory Synchronization Spin Locks Barriers Semaphores Monitors 2 1 Memory Architectures Distributed Memory Shared Memory

More information

Chapter 5: Process Synchronization

Chapter 5: Process Synchronization Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Operating System Concepts 9th Edition Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution

More information

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition

Chapter 5: Process Synchronization. Operating System Concepts 9 th Edition Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks

More information

Chapter 6: Process Synchronization. Module 6: Process Synchronization

Chapter 6: Process Synchronization. Module 6: Process Synchronization Chapter 6: Process Synchronization Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization

More information

Deadlock. INF2140 Parallel Programming: Lecture 6. March 07, INF2140 Parallel Programming: Lecture 6 Deadlock

Deadlock. INF2140 Parallel Programming: Lecture 6. March 07, INF2140 Parallel Programming: Lecture 6 Deadlock March 07, 2012 Concepts System deadlock: no further progress Four necessary & sufficient conditions Models - no eligible actions Practice Blocked threads Aim: deadlock avoidance - to design systems where

More information

Synchronization Principles

Synchronization Principles Synchronization Principles Gordon College Stephen Brinton The Problem with Concurrency Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms

More information

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background

Background. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background Module 6: Process Synchronization Background Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization

More information

An Anonymous Self-Stabilizing Algorithm For 1-Maximal Matching in Trees

An Anonymous Self-Stabilizing Algorithm For 1-Maximal Matching in Trees An Anonymous Self-Stabilizing Algorithm For 1-Maximal Matching in Trees Wayne Goddard, Stephen T. Hedetniemi Department of Computer Science, Clemson University {goddard,hedet}@cs.clemson.edu Zhengnan Shi

More information

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition,

Chapter 6: Process Synchronization. Operating System Concepts 8 th Edition, Chapter 6: Process Synchronization, Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores

More information

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization? Chapter 6: Process [& Thread] Synchronization CSCI [4 6] 730 Operating Systems Synchronization Part 1 : The Basics Why is synchronization needed? Synchronization Language/Definitions:» What are race conditions?»

More information

Concurrency. Chapter 5

Concurrency. Chapter 5 Concurrency 1 Chapter 5 2 Concurrency Is a fundamental concept in operating system design Processes execute interleaved in time on a single processor Creates the illusion of simultaneous execution Benefits

More information

Petri Nets. Robert A. McGuigan, Department of Mathematics, Westfield State

Petri Nets. Robert A. McGuigan, Department of Mathematics, Westfield State 24 Petri Nets Author: College. Robert A. McGuigan, Department of Mathematics, Westfield State Prerequisites: The prerequisites for this chapter are graphs and digraphs. See Sections 9.1, 9.2, and 10.1

More information

6.852: Distributed Algorithms Fall, Class 12

6.852: Distributed Algorithms Fall, Class 12 6.852: Distributed Algorithms Fall, 2009 Class 12 Today s plan Weak logical time and vector timestamps Consistent global snapshots and stable property detection. Applications: Distributed termination.

More information

CS 6783 (Applied Algorithms) Lecture 5

CS 6783 (Applied Algorithms) Lecture 5 CS 6783 (Applied Algorithms) Lecture 5 Antonina Kolokolova January 19, 2012 1 Minimum Spanning Trees An undirected graph G is a pair (V, E); V is a set (of vertices or nodes); E is a set of (undirected)

More information

Process Synchronization

Process Synchronization CS307 Process Synchronization Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2018 Background Concurrent access to shared data may result in data inconsistency

More information