distributed algorithms distributed algorithms
play

Distributed Algorithms Distributed Algorithms Distributed Mutual - PowerPoint PPT Presentation

Distributed Algorithms Distributed Algorithms Distributed Mutual Exclusion Olivier Dalle (*) olivier.dalle@sophia.inria.fr (*) Large parts of this lecture borrowed from Sukumar Ghosh's book. Olivier Dalle 1 Distributed Algorithms Mutual


  1. Distributed Algorithms Distributed Algorithms Distributed Mutual Exclusion Olivier Dalle (*) olivier.dalle@sophia.inria.fr (*) Large parts of this lecture borrowed from Sukumar Ghosh's book. Olivier Dalle 1 Distributed Algorithms – Mutual Exclusion

  2. Distributed Mutual Exclusion Distributed Mutual Exclusion Mostly from Sukumar Ghosh's book and handsout: Mostly from Sukumar Ghosh's book and handsout: 1 – Introduction 1 – Introduction 2 – Solutions Using Message Passing 2 – Solutions Using Message Passing 3 – Token Passing Algorithms 3 – Token Passing Algorithms 4 – The Group Mutual Exclusion Problem 4 – The Group Mutual Exclusion Problem Also in Ghosh's book (not covered by this lecture): Also in Ghosh's book (not covered by this lecture): Solution on the shared memory model Solution on the shared memory model Peterson algorithm Peterson algorithm Mutual exclusion using special instruction Mutual exclusion using special instruction Solution using Test-and-Set Solution using Test-and-Set Solution using DEC LL and SC instruction Solution using DEC LL and SC instruction Olivier Dalle 2 Distributed Algorithms – Mutual Exclusion

  3. Distributed Mutual Exclusion Distributed Mutual Exclusion 1 – Introduction Introduction 1 – 2 – Solutions Using Message Passing 2 – Solutions Using Message Passing 3 – Token Passing Algorithms 3 – Token Passing Algorithms 4 – The Group Mutual Exclusion Problem 4 – The Group Mutual Exclusion Problem Olivier Dalle 3 Distributed Algorithms – Mutual Exclusion

  4. 1- Introduction Why Do We Need Distributed Mutual Exclusion (DME) ? Why Do We Need Distributed Mutual Exclusion (DME) ? Atomicity exists only up to a certain level: Atomicity exists only up to a certain level: Atomic instructions Atomic instructions Defines the granularity of the computation Defines the granularity of the computation Types of possible interleaving Types of possible interleaving Assembly Language Instruction? Assembly Language Instruction? Remote Procedure Call? Remote Procedure Call? Olivier Dalle 4 Distributed Algorithms – Mutual Exclusion

  5. 1- Introduction Why Do We Need Distributed Mutual Exclusion (DME) ? Why Do We Need Distributed Mutual Exclusion (DME) ? Some applications are: Some applications are: • Resource sharing Resource sharing • Avoiding concurrent update on shared data Avoiding concurrent update on shared data • Controlling the grain of atomicity Controlling the grain of atomicity • Medium Access Control in Ethernet Medium Access Control in Ethernet • Collision avoidance in wireless broadcasts Collision avoidance in wireless broadcasts Olivier Dalle 5 Distributed Algorithms – Mutual Exclusion

  6. 1- Introduction Why Do We Need Distributed Mutual Exclusion (DME) ? Why Do We Need Distributed Mutual Exclusion (DME) ? Example: Bank Account Operations Example: Bank Account Operations shared n : integer Process P Process Q Account receives amount nP Account receives amount nQ Computation: n = n +nP: Computation: n = n +nQ: P1. Load Reg_P , n Q1. Load Reg_Q, n P2. Add Reg_P , nP Q2. Add Reg_Q, nQ P3. Store Reg_P , n Q3. Store Reg_Q, n Olivier Dalle 6 Distributed Algorithms – Mutual Exclusion

  7. 1- Introduction Why Do We Need DME? (example cont'd) Why Do We Need DME? (example cont'd) Possible Interleaves of Executions of P and Q: Possible Interleaves of Executions of P and Q: 2 give the expected result n= n + nP + nQ 2 give the expected result n= n + nP + nQ P1, P2, P3, Q1, Q2, Q3 P1, P2, P3, Q1, Q2, Q3 Q1, Q2, Q3, P1, P2, P3 Q1, Q2, Q3, P1, P2, P3 5 give erroneous result n = n+nQ 5 give erroneous result n = n+nQ P1, Q1, P2, Q2, P3, Q3 P1, Q1, P2, Q2, P3, Q3 P1, P2, Q1, Q2, P3, Q3 P1, P2, Q1, Q2, P3, Q3 P1, Q1, Q2, P2, P3, Q3 P1, Q1, Q2, P2, P3, Q3 Q1, P1, Q2, P2, P3, Q3 Q1, P1, Q2, P2, P3, Q3 Q1, Q2, P1, P2, P3, Q3 Q1, Q2, P1, P2, P3, Q3 5 give erroneous result n = n + nP 5 give erroneous result n = n + nP Q1, P1, Q2, P2, Q3, P3 Q1, P1, Q2, P2, Q3, P3 Q1, Q2, P1, P2, Q3, P3 Q1, Q2, P1, P2, Q3, P3 Q1, P1, P2, Q2, Q3, P3 Q1, P1, P2, Q2, Q3, P3 P1, Q1, P2, Q2, Q3, P3 P1, Q1, P2, Q2, Q3, P3 P1, P2, Q1, Q2, Q3, P3 P1, P2, Q1, Q2, Q3, P3 Olivier Dalle 7 Distributed Algorithms – Mutual Exclusion

  8. 1- Introduction Solutions to the Mutual Exclusion Problem Solutions to the Mutual Exclusion Problem p0 CS p1 CS p2 CS p3 CS Olivier Dalle 8 Distributed Algorithms – Mutual Exclusion

  9. 1- Introduction Solutions to the Mutual Exclusion Problem (2) Solutions to the Mutual Exclusion Problem (2) 2 classes of solutions: 2 classes of solutions: Ad hoc solutions Ad hoc solutions Solutions based on non-preemptible resource allocation Solutions based on non-preemptible resource allocation Both classes require a special code around the critical Both classes require a special code around the critical section section Ad-hoc case Non-preempt. resource case Enter protocol Request resource <critical section> <critical section> Exit protocol Release resource Olivier Dalle 9 Distributed Algorithms – Mutual Exclusion

  10. Distributed Mutual Exclusion Distributed Mutual Exclusion 1 – Introduction 1 – Introduction 2 – Solutions Using Message Passing 2 – Solutions Using Message Passing 3 – Token Passing Algorithms 3 – Token Passing Algorithms 4 – The Group Mutual Exclusion Problem 4 – The Group Mutual Exclusion Problem Olivier Dalle 10 Distributed Algorithms – Mutual Exclusion

  11. 2- Solutions Using Message Passing Introduction Introduction Problem formulation Problem formulation Assumptions Assumptions n processes (n>1), numbered 0 ... n-1, noted Pi n processes (n>1), numbered 0 ... n-1, noted Pi form a distributed system form a distributed system topology: completely connected graph (Kn) topology: completely connected graph (Kn) each Pi periodically each Pi periodically wants: wants: 1. enter the Critical Section (CS) enter the Critical Section (CS) 2. execute the CS code execute the CS code 3. eventually exits the CS code eventually exits the CS code Devise a protocol that satisfies: Devise a protocol that satisfies: ME1 : Mutual Exclusion ME1 : Mutual Exclusion ME2 : Freedom from deadlock ME2 : Freedom from deadlock ME3 : Progress ME3 : Progress Olivier Dalle 11 Distributed Algorithms – Mutual Exclusion

  12. 2- Solutions Using Message Passing Introduction (2) Introduction (2) Zoom on Conditions... Zoom on Conditions... ME1 : Mutual Exclusion ME1 : Mutual Exclusion At most one process can remain in CS at any time At most one process can remain in CS at any time Safety property Safety property ME2 : Freedom from deadlock ME2 : Freedom from deadlock At least one process is eligible to enter CS At least one process is eligible to enter CS Safety property Safety property ME3 : Progress ME3 : Progress Every process trying to enter must eventually succeed Every process trying to enter must eventually succeed Liveness property Liveness property Violation called livelock livelock or or starvation starvation Violation called A measure of fairness: bounded waiting A measure of fairness: bounded waiting Specifies an upper bound on the number of times a process waits for its turn Specifies an upper bound on the number of times a process waits for its turn to enter SC to enter SC Olivier Dalle 12 Distributed Algorithms – Mutual Exclusion

  13. 2- Solutions Using Message Passing Introduction (3) Introduction (3) Centralized Solutions? Centralized Solutions? server Use a coordinator process Use a coordinator process External process External process busy: boolean One of the Pi-s One of the Pi-s queue Problems: Problems: release req reply Single point of failure Single point of failure Unable to achieve FIFO fairness Unable to achieve FIFO fairness S C clients e t g s Example: Example: a e s u s q S e e C m r t s i e u How to anticipate q e r this late arrival? j coor d Olivier Dalle 13 Distributed Algorithms – Mutual Exclusion

  14. 2- Solutions Using Message Passing Lamport's Solution Lamport's Solution Assumptions: Assumptions: Each communicaion channel is FIFO Each communicaion channel is FIFO Each process maintains a request queue Q Each process maintains a request queue Q Algorithm described by 5 rules Algorithm described by 5 rules LA1. To request entry, send a time-stamped message to every LA1. To request entry, send a time-stamped message to every other other process and process and enqueue to local Q enqueue to local Q LA2. Upon reception place request in Q and send time-stamped ACK LA2. Upon reception place request in Q and send time-stamped ACK but once out of CS once out of CS but (possibly immediately if already out) (possibly immediately if already out) LA3. Enter CS when: LA3. Enter CS when: 1. request first in Q (chronological order) request first in Q (chronological order) 2. all ACK received from others all ACK received from others LA4. To exit CS, a process must: LA4. To exit CS, a process must: 1. delete request from Q delete request from Q 2. send time-stamped release message to others send time-stamped release message to others LA5. When receiving a release msg, remove request from Q LA5. When receiving a release msg, remove request from Q Olivier Dalle 14 Distributed Algorithms – Mutual Exclusion

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend