Resource Allocation. Centralized Mutex Algorithm Send requests to Leader Leader maintains a pending queue of events Requests are granted in the order.

Slides:



Advertisements
Similar presentations
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Distributed Mutual Exclusion.
Advertisements

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.
Chapter 12 Message Ordering. Causal Ordering A single message should not be overtaken by a sequence of messages Stronger than FIFO Example of FIFO but.
Chapter 13 Leader Election. Breaking the symmetry in system Similar to distributed mutual exclusion problems, the first process to enter the CS can be.
CS542 Topics in Distributed Systems Diganta Goswami.
Ricart and Agrawala’s Algorithm
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
© 2004, D. J. Foreman 1 The Dining Philosophers Problem.
Chap 16. Transactions. Transactions Transaction: sequence of operations such that the entire sequence appears as one indivisible operation Indivisibility.
Chapter 18 Self-Stabilization. Introduction Self-stabilization: Tolerate ‘data faults’  Example: Parent pointers in a spanning tree getting corrupted.
UBE529 Distributed Algorithms Self Stabilization.
Page 1 Mutual Exclusion* Distributed Systems *referred to slides by Prof. Paul Krzyzanowski at Rutgers University and Prof. Mary Ellen Weisskopf at University.
Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within.
Operating Systems, 112 Practical Session 14, Distributed synchronization.
Enforcing Mutual Exclusion Message Passing. Peterson’s Algorithm for Processes P0 and P1 void P0() { while( true ) { flag[ 0 ] = false; /* remainder */
CS 582 / CMPE 481 Distributed Systems
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Operating Systems, 2011, Danny Hendler & Amnon Meisels 1 Distributed Mutual Exclusion  Introduction  Ricart and Agrawala's algorithm  Raymond's algorithm.
Chapter 11 Detecting Termination and Deadlocks. Motivation – Diffusing computation Started by a special process, the environment environment sends messages.
Distributed Mutual Exclusion Béat Hirsbrunner References G. Coulouris, J. Dollimore and T. Kindberg "Distributed Systems: Concepts and Design", Ed. 4,
Chapter 14 Synchronizers. Synchronizers : Introduction Simulate a synchronous network over an asynchronous underlying network Possible in the absence.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Distributed Mutual Exclusion.
Distributed Mutual Exclusion
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 2 (19/01/2006) Instructor: Haifeng YU.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo.
© 2004, D. J. Foreman 1 High Level Synchronization and Inter-Process Communication.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo.
UBE529 Resource Allocation. 2 Resource Allocation : Schedule The Critical-Section Problem Synchronization Hardware Semaphores Algorithms Distributed Mutual.
Chapter 9 Global Snapshot. Global state  A set of local states that are concurrent with each other Concurrent states: no two states have a happened before.
MUTUAL EXCLUSION AND QUORUMS CS Distributed Mutual Exclusion Given a set of processes and a single resource, develop a protocol to ensure exclusive.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
CS425 /CSE424/ECE428 – Distributed Systems – Fall 2011 Material derived from slides by I. Gupta, M. Harandi, J. Hou, S. Mitra, K. Nahrstedt, N. Vaidya.
Coordination and Agreement. Topics Distributed Mutual Exclusion Leader Election.
1 Distributed Process Management Chapter Distributed Global States Operating system cannot know the current state of all process in the distributed.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of.
ITEC452 Distributed Computing Lecture 6 Mutual Exclusion Hwajung Lee.
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.
A: A: double “4” A: “34” 4.
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
Lecture 12-1 Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2012 Indranil Gupta (Indy) October 4, 2012 Lecture 12 Mutual Exclusion.
Lecture 7- 1 CS 425/ECE 428/CSE424 Distributed Systems (Fall 2009) Lecture 7 Distributed Mutual Exclusion Section 12.2 Klara Nahrstedt.
Decentralized solution 1
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: –Mutual exclusion.
CS 425 / ECE 428 Distributed Systems Fall 2015 Indranil Gupta (Indy) Oct 1, 2015 Lecture 12: Mutual Exclusion All slides © IG.
Distributed Mutual Exclusion
Practical Session 13 Distributed synchronization
Distributed Mutex EE324 Lecture 11.
Distributed Mutual Exclusion
Decentralized solution 1
Raymond Exclusive Algorithm
Mutual Exclusion Problem Specifications
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Outline Distributed Mutual Exclusion Introduction Performance measures
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
CSE 486/586 Distributed Systems Mutual Exclusion
Synchronization (2) – Mutual Exclusion
Prof. Leonardo Mostarda University of Camerino
Distributed Mutual Exclusion
Distributed Systems and Concurrency: Synchronization in Distributed Systems Majeed Kassis.
Distributed Mutual eXclusion
CSE 486/586 Distributed Systems Mutual Exclusion
Presentation transcript:

Resource Allocation

Centralized Mutex Algorithm Send requests to Leader Leader maintains a pending queue of events Requests are granted in the order they are received

// Centralized mutex algorithm public class CentMutex extends Process implements Lock {... public synchronized void requestCS() { sendMsg(leader, "request"); while (!haveToken) myWait(); } public synchronized void releaseCS() { sendMsg(leader, "release"); haveToken = false; } public synchronized void handleMsg(Msg m, int src, String tag) { if (tag.equals("request")) { if (haveToken){ sendMsg(src, "okay"); haveToken = false; } else pendingQ.add(src); } else if (tag.equals("release")) { if (!pendingQ.isEmpty()) { int pid = pendingQ.removeHead(); sendMsg(pid, "okay"); } else haveToken = true; } else if (tag.equals("okay")) { haveToken = true; notify(); }

Lamport’s Algorithm Ensures that processes enter the critical section in the order of timestamps of their requests Requires 3(N-1) messages per invocation of the critical section

// Lamport’s mutual exclusion algorithm public class LamportMutex extends Process implements Lock { public synchronized void requestCS() { v.tick(); q[myId] = v.getValue(myId); broadcastMsg("request", q[myId]); while (!okayCS()) myWait(); } public synchronized void releaseCS() { q[myId] = Symbols.Infinity; broadcastMsg("release", v.getValue(myId)); } boolean okayCS() { for (int j = 0; j < N; j++){ if(isGreater(q[myId], myId, q[j], j)) return false; if(isGreater(q[myId], myId, v.getValue(j), j))return false; } return true; } public synchronized void handleMsg(Msg m, int src, String tag) { int timeStamp = m.getMessageInt(); v.receiveAction(src, timeStamp); if (tag.equals("request")) { q[src] = timeStamp; sendMsg(src, "ack", v.getValue(myId)); } else if (tag.equals("release")) q[src] = Symbols.Infinity; notify(); // okayCS() may be true now }

Ricart and Agrawala’s algorithm Combines the functionality of acknowledgement and release messages Uses only 2(N-1) messages per invocation of the critical section

public class RAMutex extends Process implements Lock { public synchronized void requestCS() { c.tick(); myts = c.getValue(); broadcastMsg("request", myts); numOkay = 0; while (numOkay < N-1) myWait(); } public synchronized void releaseCS() { myts = Symbols.Infinity; while (!pendingQ.isEmpty()) { int pid = pendingQ.removeHead(); sendMsg(pid, "okay", c.getValue()); } public synchronized void handleMsg(Msg m, int src, String tag) { int timeStamp = m.getMessageInt(); c.receiveAction(src, timeStamp); if (tag.equals("request")) { if ((myts == Symbols.Infinity ) || (timeStamp < myts) ||((timeStamp == myts)&&(src<myId )))//not interested in CS sendMsg(src, "okay", c.getValue()); else pendingQ.add(src); } else if (tag.equals("okay")) { numOkay++; if (numOkay == N - 1) notify(); // okayCS() may be true now } }}

Dining Philosopher Algorithm Eating rule: A process can eat only when it is a source Edge reversal: After eating, reverse orientations of all the outgoing edges

public class DinMutex extends Process implements Lock { public synchronized void requestCS() { myState = hungry; if (haveForks()) myState = eating; else for (int i = 0; i < N; i++) if (request[i] && !fork[i]) { sendMsg(i, "Request"); request[i] = false; } while (myState != eating) myWait(); } public synchronized void releaseCS() { myState = thinking; for (int i = 0; i < N; i++) { dirty[i] = true; if (request[i]) { sendMsg(i, "Fork"); fork[i] = false; } } boolean haveForks() { for (int i = 0; i < N; i++) if (!fork[i]) return false; return true; } public synchronized void handleMsg(Msg m, int src, String tag) { if (tag.equals("Request")) { request[src] = true; if ((myState != eating) && fork[src] && dirty[src]) { sendMsg(src, "Fork"); fork[src] = false; if (myState == hungry){ sendMsg(src, "Request"); request[src] = false; } } else if (tag.equals("Fork")) { fork[src] = true; dirty[src] = false; if (haveForks()) { myState = eating; notify(); } } } }

Token based algorithm Use a token for resource allocation problems A process needs the token to access the critical section

public class CircToken extends Process implements Lock { public synchronized void initiate() { if (haveToken) sendToken(); } public synchronized void requestCS() { wantCS = true; while (!haveToken) myWait(); } public synchronized void releaseCS() { wantCS = false; sendToken(); } void sendToken() {... } public synchronized void handleMsg(Msg m, int src, String tag) { if (tag.equals("token")) { haveToken = true; if (wantCS) notify(); else { Util.mySleep(1000); sendToken(); }

Quorum based algorithms Request permission from a subset of processes Crumbling walls