Bakery Algorithm - Proof

Slides:



Advertisements
Similar presentations
Mutual Exclusion – SW & HW By Oded Regev. Outline: Short review on the Bakery algorithm Short review on the Bakery algorithm Black & White Algorithm Black.
Advertisements

CSC321 Concurrent Programming: §3 The Mutual Exclusion Problem 1 Section 3 The Mutual Exclusion Problem.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Process Synchronization Continued 7.2 The Critical-Section Problem.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
1 Chapter 2 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2007 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
1 Course Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation.
1 Algorithms and protocols for distributed systems We have defined process groups as having peer or hierarchical structure and have seen that a coordinator.
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
CPSC 668Set 7: Mutual Exclusion with Read/Write Variables1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
Multiprocess Synchronization Algorithms ( )
The Critical-Section Problem
1 Course Syllabus 1. Introduction - History; Views; Concepts; Structure 2. Process Management - Processes; State + Resources; Threads; Unix implementation.
CS 582 / CMPE 481 Distributed Systems
What we will cover…  Distributed Coordination 1-1.
1 Tuesday, June 20, 2006 "The box said that I needed to have Windows 98 or better... so I installed Linux." - LinuxNewbie.org.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
OS Spring’04 Concurrency Operating Systems Spring 2004.
Concurrency in Distributed Systems: Mutual exclusion.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
1 Lecture 9: Synchronization  concurrency examples and the need for synchronization  definition of mutual exclusion (MX)  programming solutions for.
The Critical Section Problem
1 Synchronization (1) Dave Eckhardt
Mutual Exclusion Presented by: Rohan Sen (Distributed Algorithms Ch. 10)
28/10/1999POS-A1 The Synchronization Problem Synchronization problems occur because –multiple processes or threads want to share data; –the executions.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
1 Chapter 10 Distributed Algorithms. 2 Chapter Content This and the next two chapters present algorithms designed for loosely-connected distributed systems.
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
Mutual Exclusion Using Atomic Registers Lecturer: Netanel Dahan Instructor: Prof. Yehuda Afek B.Sc. Seminar on Distributed Computation Tel-Aviv University.
1 Chapter 2 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2014 Synchronization Algorithms and Concurrent Programming Synchronization.
1 Concurrent Processes. 2 Cooperating Processes  Operating systems allow for the creation and concurrent execution of multiple processes  concurrency.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-5 Process Synchronization Department of Computer Science and Software.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are: 1. Resource sharing 2. Avoiding concurrent update on shared data 3. Controlling the.
Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch.
Lecture 4 Correctness and Fairness Verification and Assurance.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
Decentralized solution 1
SOCSAMS e-learning Dept. of Computer Applications, MES College Marampally INTERPROCESS COMMUNICATION AND SYNCHRONIZATION SYNCHRONIZATION.
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.
6.852: Distributed Algorithms Spring, 2008 Class 14.
Chapter 10 Mutual Exclusion Presented by Yisong Jiang.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
OS Winter’03 Concurrency. OS Winter’03 Bakery algorithm of Lamport  Critical section algorithm for any n>1  Each time a process is requesting an entry.
Bakery Algorithm - Proof
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Designing Parallel Algorithms (Synchronization)
Concurrent Distributed Systems
Decentralized solution 1
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
The Critical-Section Problem
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Lecture 20 Syed Mansoor Sarwar
Mutual Exclusion Problem Specifications
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
Group Mutual Exclusion & Hadzilacos Algorithm
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Multiprocessor Synchronization Algorithms ( )
Lecture 21 Syed Mansoor Sarwar
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Syllabus 1. Introduction - History; Views; Concepts; Structure
Presentation transcript:

Bakery Algorithm - Proof OS Winter’06

Bakery algorithm for n processes D T-D C E OS Winter’03

Structure of the algorithm R – code prior to using Bakery algorithm T – creating of a ticket and awaiting for permission to enter critical section D – creation of a number (first part of a ticket) T-D – awaiting for the permission to enter critical section C – critical section itself E – code executed upon exit from critical section OS Winter’03

Basic Lemma Lemma 1: OS Winter’03

Lemma 1 - proof Denote ‘s’ time point where lemma’s conditions hold At time ‘s’, is in C (critical section) number[i] has been selected and still exists number[j] has been selected and still exists Exist time point ‘t1’<‘s’, where performs a check (choosing[j]==0) and passes it Exists time point ‘t2’, t1<t2<s, where performs a check (number[j]!=0) and (number[i],i)<(number[j],j) OS Winter’03

Lemma 1 – proof (cont) Since at time ‘t1’ exists (choosing[j]==0) one of the following has to be true CASE A: number[j] was chosen after time ‘t1’ and before time ‘s’ CASE B: number[j] was chosen before ‘t1’ OS Winter’03

Lemma 1 – proof – CASE A Since at time ‘t1’ already checks for permission to enter critical section, computation of number[i] was computed before that and persists until ‘s’ Thus, at the time starts to compute its number[j], it has to take into account of ‘max’ value of number[i]. So it creates a value which is greater then number[i] at least by 1, and it persists until time ‘s’ That is (number[i],i)<(number[j],j) at time ‘s’ OS Winter’03

Lemma 1 – proof – CASE B Both number[i] and number[j] were computed before ‘t1’, thus also before time ‘t2’ and persisted until ‘s’ At time ‘t2’ performed check (number[j]!=0) & (number[j],j)<(number[i],i), which failed, since is in C at time ‘s’ number[j] was chosen before ‘t2’ and persisted, thus first part of the check could not fail, also ‘i’ and ‘j’ are different, so (number[i],i)<(number[j],j) at time ‘s’ OS Winter’03

Lemmata 2,3,4 Lemma 2 – mutual exclusion: Lemma 3 – progress Bakery Algorithm satisfies mutual exclusion property Lemma 3 – progress Bakery Algorithm guarantees progress Lemma 4 – fairness Bakery Algorithm guarantees lockout-freedom OS Winter’03

Lemma 2 – Proof Assume in contradiction that there are two different processes that have entered critical section Then conditions of Lemma 1 are true for both processes simmetrically that is (number[i],i)<(number[j],j]) and (number[j],j)<(number[i],i) : contradiction We conclude that mutual exclusion is satisfied OS Winter’03

Lemma 3 – Proof Suppose progress is not guaranteed Then eventually a point is reached after which all processes are in T or R By the code, all the processes in T eventually complete D and reach T-D Then the process with the lowest (number,ID) pair is not blocked from reaching C, that is enters critical section We conclude that Bakery algorithm satisfies Progress OS Winter’03

Lemma 4 – Proof Consider a particular process in T and suppose it never reaches C The process eventually completes D and reaches T-D After that any new process that enters D perceives number[i] and chooses a higher number Thus, since does not reach C, none of these new processes reach C either But by Lemma 3 there must be continuing progress, that is infinitely many entries to C Contradiction: blocks the entry to C OS Winter’03

Remark on Fairness A process that obtained a ticket (number[k],k) will wait at most for (n-1) turns, when other processes will enter the critical section For example if all the processes obtained their tickets at the same time they will look like (q,1),(q,2)…(q,n) In which case process will wait for processes … to complete the critical section OS Winter’03

Bibliography Nancy Ann Lynch, “Distributed Algorithms”, JMC 243.9 LY53 Leslie Lamport “A new solution of Dijkstra’s concurrent programming problem” Communications of the ACM 17(8):453-455, 1974 OS Winter’03