Distributed Algorithms - Ricart Agrawala Mutual Exclusion 2000-06-26 Thomas Lehner, Rene Mayrhofer Distributed Algorithms - Ricart Agrawala Mutual Exclusion.

Slides:



Advertisements
Ähnliche Präsentationen
der Universität Oldenburg
Advertisements

Klassen - Verkettete Liste -
Geometrische Datenstrukturen Haozhe Chen Aaron Richardson.
Ein Beispiel in Java.
PKJ 2005/1 Stefan Dissmann Vorwoche - Klasse public class Studierende { private String name, vorname, studiengang; private int matNr, semester; private.
Suche in Texten (Stringsuche )
Peter Marwedel TU Dortmund, Informatik 12
3 Prozessverwaltung  sieht einen Prozess als Objekt der Verwaltung,
Verteilte Software - Java - Prozedurale Programmierung 1
Gliederung Motivation / Grundlagen Sortierverfahren
Sortieren mit Binären Bäumen
Java: Dynamische Datentypen
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (13 – Offenes Hashing) Prof. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (06 - Anwendungen von Stapeln und Schlangen) Prof. Th. Ottmann.
Vorlesung Informatik 2 Algorithmen und Datenstrukturen (05 – Elementare Datenstrukturen) Prof. Th. Ottmann.
Informatik II, SS 2008 Algorithmen und Datenstrukturen Vorlesung 6 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Benötigte Applets Startseite: in HTML-Format Applet auf der Startseite Das Applet, das auf der Startseite geladen wird, wird die vier Buttons und die eine.
1 Named Pipes alias FIFO Haben einen Eintrag im Dateisystem und sind somit durch Zugriffsrechte identifizierbar Ermöglichen die Kommunikation zwischen.
Institut für Kartographie und Geoinformation Prof.-Dr. Lutz Plümer, Dr. Gerhard Gröger, Dipl.-Ing. Dirk Dörschlag Einführung in die Programmierung mit.
PRJ 2007/1 Stefan Dissmann Motivation Problem: gleiche Datenstrukturen werden für verschiedene Objekte gebraucht: z.B. Listen von Studierenden, Kunden,
PKJ 2005/1 Stefan Dissmann Klassenhierarchie Person Kunde Goldkunde Lieferant Object.
Listen Prof. Dr. Christian Böhm in Zusammenarbeit mit Gefei Zhang
Projektplan: Fachgebiet Software Engineering Übersicht © Albert Zündorf, Kassel University.
Modulare Programmierung
DVG Klassen und Objekte
DVG Einfache Klassen 1 Einfache Klassen. 2DVG Einfache KlassenStrukturen Beispiel: Personendaten bestehen aus String name String name.
EDV Parallelprogrammierung1 Parallelprogrammierung mit JAVA.
Java in 9 Folien Besser: Online-Buch Go to Java 2.
Einführung in die Programmierung Datensammlung
Informatikunterricht mit Java
Template Pattern Richard Göbel.
Seite 1 Interface - Konzept Ein Interface führt einen neuen Datentyp ein: interface Frau {... } Das Interface enthält Deklarationen ( keine Definitionen.
1000 Km bis zum Meer. “1000 Km to the sea” Luxuslärm
Ich bau eine Stadt für dich “I am building a city for you”
Informatik 1 Übung 8. NACHBESPRECHUNG Übung 8 Rekursion Existiert Weg von A nach B?
Abteilung für Telekooperation Übung Softwareentwicklung 1 für Wirtschaftsinformatik Dr. Wieland Schwinger
Abteilung für Telekooperation Übung Softwareentwicklung 1 für Wirtschaftsinformatik Dr. Wieland Schwinger
Javakurs FSS 2012 Lehrstuhl Stuckenschmidt
Javakurs FSS 2012 Lehrstuhl Stuckenschmidt
Abteilung für Telekooperation Übung Softwareentwicklung 1 für Wirtschaftsinformatik Dr. Wieland Schwinger
Dynamische Datentypen
Purga - Scriptengine Ein Einblick.
CuP - Java Sechste Vorlesung Entspricht ungefähr Kapitel 3. 1 – 3
Learning By Doing Parallelverarbeitung Multithreading (Nebenläufigkeit) Alte Idee der Parallelverarbeitung statt rein sequentieller Prozesse Parallelverarbeitung.
Passiv What are these sentences expressing?
Launch ON Global.vi System ID object name classname Services to suscribe Observer Control Ref vi-path Service name Step 1 : Objects register to the Global.vi´s,
Mag. Thomas Hilpold, Universität Linz, Institut für Wirtschaftsinformatik – Software Engineering 1 Programmierpraktikum Java SS 2005 Mag.Thomas Hilpold.
Coordinating Conjunctions Why we need them & how to use them deutschdrang.com.
Java Syntaxdiagramme Buchstabe A B Z a z ... Ziffer
Alois Schütte Advanced System Programming 2 Interprozeßkommunikation  2.1 JVM Ablaufumgebung  2.2 Java Native Interface (JNI)  Verwendung von.
Qualitätssicherung von Software Prof. Dr. Holger Schlingloff Humboldt-Universität zu Berlin und Fraunhofer FIRST.
Hier und da komm ich auf die Idee Hier und da komm ich auf die Idee Here and there I get the idea Ein andern Weg zu gehen To go on another path Mal verspielt.
Ausnahmen Vorlesung besteht aus zwei Teilen Programmierung (4 SWS)
Java-Kurs - 4. Übung Hausaufgabe Weitere Kontrollstrukturen
Mag. Thomas Hilpold, Universität Linz, Institut für Wirtschaftsinformatik – Software Engineering 1 Algorithmen und Datenstrukturen 1 SS 2002 Mag.Thomas.
3 Interaktion über Objekte. 3.1 Sperrsynchronisation dient der Vermeidung unkontrollierter nebenläufiger Zugriffe auf gemeinsame Datenobjekte und der.
Programmierkurs JavaUE 4 Anweisungen und ProgrammeDietrich BolesSeite 1 Programmierkurs Java Dr. Dietrich Boles Teil Imperative Programmierung Unterrichtseinheit.
Montag den 8. Juni Lernziel:- To launch a project and receive results.
Kapitel 2 Grammar INDEX 1.Subjects & Verbs 2.Conjugation of Verbs 3.Subject Verb Agreement 4.Person and Number 5.Present Tense 6.Word Order: Position of.
10.3 Lektion 10 Geschichte und Gesellschaft STRUKTUREN © and ® 2012 Vista Higher Learning, Inc Der Konjunktiv I and indirect speech —Ich komme.
Kapitel 9 Grammar INDEX 1.Formal Sie- Command 2.There Is/There Are 3.Negation: Nicht/Klein.
Programmiersprachen II Graph_Algorithmen Einführung Prof. Dr. Reiner Güttler Fachbereich GIS HTW.
ENVIRONMENT PROBLEMS What can I do? Pineapples Traffic  Use public vehicles  Use more bike and go by walking  There should be a filter in every car.
G Stunde DEUTSCH 1.  Unit: Family & homeFamilie & Zuhause  Objectives:  Phrases about date, weather and time-telling  Family and family relations.
Dr. Wolfram Amme, Generisches Programmieren, Informatik II, FSU Jena, SS Generisches Programmieren.
1Crypto AG / P_M_HC-2650-Course-Notes-d_0833_rd.PPT Training and Education HC-2650 Kursunterlagen.
Folder checken Ratschläge (advice) für zukünftige (future) Schüler, wenn du die das letzte mal nicht gemacht hast (if you did not have time for this last.
Fitness. An english presentation.
1.Event Queue.
Wie viel Uhr ist es? Telling Time.
 Präsentation transkript:

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer Distributed Algorithms - Ricart Agrawala Mutual Exclusion Datum: 26. Juni 2000 Vortragende: Thomas Lehner Rene Mayrhofer

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer Problemstellung gegeben: - asynchrones Netzwerk - eine Ressource - mehrere konkurrierende Prozesse und deren User gewünscht: - immer nur ein Prozess greift zugleich auf Ressource zu Beispiel: Drucker Grundlegende Idee des Ricart Agrawala Algorithmus: - Einführung einer Critical Region - Prozesse dürfen nur aus dieser auf Ressource zugreifen - Prozesse sprechen sich untereinander ab, so dass sich immer nur einer zugleich in der Critical Region befindet  exklusiver Zugriff auf Ressource Problemlösung

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer Problemlösung User-Prozess Interaktion:Einzuhaltende Bedingungen: Well-formedness: - die User-Prozess Interaktion ist wohlgeformt Mutual exclution: - es ist kein globaler Zustand erreichbar, in dem sich mehr als ein Prozess in C befindet Progress: - wenn kein Prozess in C und zumindest einer in T ist, dann muss irgendwann einer in C eintreten - wenn zumindest ein Prozess in E ist, erreicht irgendwann einer auch R Lockout-freedom: - wenn alle User C immer verlassen, dann kommt ein Prozess der in T ist auch irgendwann in C - jeder der in E ist kommt auch irgendwann in R

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer Der Ricart AgrawalaME Algorithmus - Jeder Prozess besitzt eine logische Uhr. Diese wird erhöht bei jedem Empfangs-/Sendeereignis und bei jeder User-Prozess Interaktion. - Es existieren die beiden Nachrichten TRY und OK. - Ein Prozess i kann nur dann in C eintreten, wenn er ein TRY- Broadcast durchgeführt hat und von alle anderen Prozessen die dazugehörigen OK’s erhielt. - Ein Prozess i darf nur dann mit einem OK auf ein (“try”,c) von j antworten wenn: 1. P i ist in E, R oder in T und das try i wurde noch nicht versand. 2. P i ist in T und (c,j)<(c´,i) mit (c´,“try“) ist letztes TRY von P i - In allen anderen Fällen wird das OK für P j zwischengespeichert und erst in E an P j versand.

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer Beweis für Safety Beweis für Mutual Exclution durch indirekte Beweisführung: Annahme: Pi und Pj sind zu gleich in C mit (c(last try i ),i)<(c(last try j ),j)  es existieren die dazugehörigen zwei TRY und OK Nachrichten, die von P j an P i bzw. von P i an P j geschickt wurden, bevor die Prozesse in C eintraten zwei Mögliche Zeitpunkte an denen das TRY von P j bei P i ankam: - i hat sein TRY noch nicht versendet: dann kann P i kein TRY mit (c,i)<(c(last try j ),j) mehr broadcasten - i hat sein TRY bereits abgeschickt: dann kann P j kein OK von P i erhalten, da ja nach Annahme gilt (c(last tryi),i)<(c(last tryj),j) und somit P i das OK zurückhält bis Region E i erreicht wird

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer Beweis für Liveness ·Beweis für Progress: (für Region E trivial) - Der Beweis für die Region T durch indirekten Beweis: Annahme: Zum Zeitpunkt a ist zumindest ein Prozess in T und keiner erreicht je C --> es existiert ein Zeitpunkt b vor a an dem alle Prozesse in R oder in T bleiben --> es existiert ein Zeitpunkt c nach b an dem alle Prozesse in T ihre TRY versand haben und keine dieser Nachrichten mehr in den Nachrichtenkanälen ist --> für einen P i in T gilt nun: (c(latest Try i ),i)<(c(latest Try j ),j) für alle P j in T Da P i nicht in C eintritt, muss es mindestens einen P j geben dessen OK fehlt Die 2 Gründe, weshalb P j das OK zurückhalten kann: - P j ist in C.  Widerspruch, da P j in R oder in T ist - P j ist in T und erhielt ein Try j mit (c(Try j ),j)<(c(latest Try k ),k) für alle P k in T (k  j)  Widerspruch, da gilt: (c(latest Try i ),i)<(c(latest Try j ),j) ·Beweis für Lockout-freedom: (für Region E trivial) - Der Beweis für die Region T durch indirekten Beweis: Annahme: P i ist in T mit versendetem TRY und tritt nie in C ein  nach dem maximal n*(c(latest try i )-1) + i-1 mal ein Prozess in C eintrat, tritt kein weiterer P j (j  i)mehr in C ein, da dann gelten würde (c(latest try j ),j)>(c(latest try i ),i)  Widerspruch zu Beweis von Progress

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer Node i ( i  {1,....., N} ): Signature: Input: try i exit i recieve(m) j, i, m  {"try", "ok"}  N, 1 <= j <= N Output: crit i rem i send(m) i, j, m  {"ok"}  N, j  i bcast(m) i, m  {"try"}  N State Variables: region i  {R, T, C, E}, initially R clock i  N, initially 0 bcast-buffer i, a FIFO queue of {"try"}, initially empty for every j, 1 <= j, <= N: history(j) i, a subset of {"try", "ok"}  N, initially {} for every j ¹ i: send-buffer(j) i, a FIFO queue of {"ok"}, initially empty deferred-ok(j) i, a FIFO queue of {"ok"}, initially empty Transitions: try i Effect: clock i := clock i + 1 region i := T add ("try") to bcast-buffer i recieve(m, c) j, i Effect: clock i := max(clock i, c) + 1 history(j) i := history(j) i  {(m, c)} if m = "try" and j  i then if region i  {E, R} or (region i = T and bcast-buffer i contains ("try")) then add ("ok") to send-buffer(j) i else if region i = C then add ("ok") to deferred-ok(j) i else if region i = T and not bcast-buffer i contains ("try") if (c', i) > (c, j) with ("try", c')  history(i) i and  (c'' with ("try", c'')  history(i) i and c'' > c') then add ("ok") to send-buffer(j) i else add ("ok") to deferred-ok(j) i Formale Spezifikation - 1

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer exit i Effect: clock i := clock i + 1 region i := E for all j  i for all (m, c) in deferred-ok(j) i add (m, c) to send-buffer(j) i clear deferred-ok(j) i crit i Precondition: region i = T for such a c that ("try", c)  history(i) i and  (c'' with ("try", c'')  history(i) i and c'' > c) for all j  i  ("ok", c')  history(j) i with (c, i) < (c', j) Effect: clock i := clock + 1 region i := C rem i Precondition: region i = E Effect: clock i := clock i +1 region i = R send(m, c) i, j Precondition: m ist first on send-buffer(j) i c = clock i + 1 Effect: clock i := clock i +1 remove first element of send-buffer(j) i bcast(m, c) i Precondition: m ist first on bcast-buffer i c = clock i + 1 Effect: clock i := clock i +1 remove first element of bcast-buffer i Tasks: { crit i } { rem i } { bcast(m) i } for every j  i: { send(m) i, j } Formale Spezifikation - 2

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer package MutualExclusion; import daj.*; import java.util.*; public class RicartAgrawala extends Application { public static final int PNUM = 6; public static final int DISTANCE = 70; public static final int BORDER = 40;.... public void construct() { Node[] nodes = new Node[PNUM]; int i, j; double phi, r = (PNUM * DISTANCE) / (2 * Math.PI); for (i=0; i<PNUM; i++) { phi = (double) i / PNUM * Math.PI * 2; nodes[i] = node(new Prog(i), new Integer(i).toString(), (int) (r * Math.cos(phi) + r + BORDER), (int) (r * Math.sin(phi) + r + BORDER)); } for (i=0; i<PNUM; i++) { for (j=0; j<PNUM; j++) { link(nodes[i], nodes[j]); }.... }

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer class Prog extends Program {... /** the node number */ protected int index; /** the region can be either R, T, C or E */ protected int region = R; /** the current clock value */ protected int clock = 0; /** for every node, the message history */ protected Vector[] history = null; /** for every neighbour, the buffer for remembering deferred ok messages until critical region has been left */ protected Vector[] deferred_ok = null; /** the logical time of the last "try" message that has been sent */ protected LogicalTime lastTryTime = null; /** the default constructor initializes the index and the arrays */ public Prog(int index) { this.index = index; history = new Vector[RicartAgrawala.PNUM]; for (int i=0; i<history.length; i++) history[i] = new Vector(); deferred_ok = new Vector[RicartAgrawala.PNUM]; for (int i=0; i<deferred_ok.length; i++) if (i != index) deferred_ok[i] = new Vector(); else deferred_ok[i] = null; }

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer public void tryRessource() { // single actions must be atomic --> synchronize them synchronized (this) { clock++; region = T; lastTryTime = new LogicalTime(clock, index); out().send(new Msg(Msg.TRY, lastTryTime)); } public void freeRessource() { synchronized (this) { clock++; // this does not match the formal specification - the release is // done immediately region = R; for (int i=0; i<deferred_ok.length; i++) if (i != index) { for (int j=0; j<deferred_ok[i].size(); j++) { out(i).send((Msg) deferred_ok[i].get(j)); } deferred_ok[i].removeAllElements(); } public void ressourceAvailable() { // for testing purposes there is no user to ne notified } public void ressourceFreed() { // for testing purposes there is no user to ne notified }

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer public void main() { Random rand = new Random(); GlobalAssertion safety = new CriticalRegionConflict(), liveness = new CriticalRegionLockout(); while (true) { assert(safety); assert(liveness); /* first the tree construction routines */ int received = in().select(2); if (received >= 0) { synchronized (this) { Msg msg = (Msg) in(received).receive(); if (msg.time.clock > clock) clock = msg.time.clock; clock++; history[received].add(msg); // respond to try requests from other nodes if (msg.type == Msg.TRY && received != index) handleTryMessage(received, msg); // check if the critical region can be entered now if (region == T && checkOkMsgsReceived()) { clock++; region = C; // the last try is invalid now lastTryTime = null; } // simulate the user here... }

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer private void handleTryMessage(int received, Msg msg) { Msg ackMsg = new Msg(Msg.OK, new LogicalTime(clock, index)); if (region == R /*|| region == E*/) out(received).send(ackMsg); else if (region == C) deferred_ok[received].add(ackMsg); else if (region == T) { if (lastTryTime != null && msg.time.lessThan(lastTryTime)) out(received).send(ackMsg); else deferred_ok[received].add(ackMsg); } private boolean checkOkMsgsReceived() { boolean receivedOkMsgs = true; for (int i=0; i<history.length; i++) { if (i != index) { int j = history[i].size() - 1; while (j >= 0 && ((Msg) history[i].get(j)).type != Msg.OK) j--; if (j >= 0) { Msg lastMsg = (Msg) history[i].get(j); if (! lastTryTime.lessThan(lastMsg.time)) receivedOkMsgs = false; } else receivedOkMsgs = false; } return receivedOkMsgs; }

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer class LogicalTime { /** the clock value */ public int clock; /** for equal clock values the sender process's index is compared */ public int process; public LogicalTime(int clock, int process) { this.clock = clock; this.process = process; } public boolean equals(Object o) { if (o instanceof LogicalTime && ((LogicalTime) o).clock == clock && ((LogicalTime) o).process == process) return true; else return false; } public boolean lessThan(LogicalTime t) { if (clock < t.clock || (clock == t.clock && process < t.process)) return true; else return false; }

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer class CriticalRegionConflict extends GlobalAssertion { private Vector procsInCR = new Vector(); public boolean assert(Program progs[]) { int numOfProcsInCR = 0; procsInCR.removeAllElements(); for (int i=0; i<progs.length; i++) { if (((Prog) progs[i]).region == Prog.C) { numOfProcsInCR++; procsInCR.add(new Integer(i)); } return numOfProcsInCR <= 1; } public String getText() { String text = "Processes in the critical region: "; for (int i=0; i<procsInCR.size(); i++) text += procsInCR.get(i) + " "; return text; }

Distributed Algorithms - Ricart Agrawala Mutual Exclusion Thomas Lehner, Rene Mayrhofer class CriticalRegionLockout extends GlobalAssertion { private LogicalTime[] tryTimes = new LogicalTime[RicartAgrawala.PNUM]; private int procInCR = -1, procTryingLonger = -1; public CriticalRegionLockout() { for (int i=0; i<tryTimes.length; i++) tryTimes[i] = null; } public boolean assert(Program progs[]) { for (int i=0; i<progs.length; i++) if (((Prog) progs[i]).region == Prog.T) tryTimes[i] = ((Prog) progs[i]).lastTryTime; // Now check when a process is in the CR, if another one is still // trying but started to try earlier. This should not happen. for (int i=0; i<progs.length; i++) if (((Prog) progs[i]).region == Prog.C) { for (int j=0; j<progs.length; j++) { if (((Prog) progs[j]).region == Prog.T && tryTimes[j].lessThan(tryTimes[i])) { procInCR = i; procTryingLonger = j; return false; } return true; }