CS 603 Process Synchronization: The Colored Ticket Algorithm February 13, 2002.

Slides:



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

Mutual Exclusion – SW & HW By Oded Regev. Outline: Short review on the Bakery algorithm Short review on the Bakery algorithm Black & White Algorithm Black.
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
1 Chapter 5 Concurrency: Mutual Exclusion and Synchronization Principals of Concurrency Mutual Exclusion: Hardware Support Semaphores Readers/Writers Problem.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Token-Dased DMX Algorithms n LeLann’s token ring n Suzuki-Kasami’s broadcast n Raymond’s tree.
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.
Concurrent Programming Problems OS Spring Concurrency pros and cons Concurrency is good for users –One of the reasons for multiprogramming Working.
1 Chapter 2 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2007 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Chapter 3 The Critical Section Problem
Page 1 Mutual Exclusion* Distributed Systems *referred to slides by Prof. Paul Krzyzanowski at Rutgers University and Prof. Mary Ellen Weisskopf at University.
Synchronization in Distributed Systems
CPSC 668Set 7: Mutual Exclusion with Read/Write Variables1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
CPSC 668Set 6: Mutual Exclusion in Shared Memory1 CPSC 668 Distributed Algorithms and Systems Fall 2006 Prof. Jennifer Welch.
Ordering and Consistent Cuts Presented By Biswanath Panda.
CPSC 668Set 6: Mutual Exclusion in Shared Memory1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
6: Process Synchronization 1 1 PROCESS SYNCHRONIZATION I This is about getting processes to coordinate with each other. How do processes work with resources.
5.6.2 Thread Synchronization with Semaphores Semaphores can be used to notify other threads that events have occurred –Producer-consumer relationship Producer.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
CS603 Process Synchronization February 11, Synchronization: Basics Problem: Shared Resources –Generally data –But could be others Approaches: –Model.
Process Synchronization
Concurrency in Distributed Systems: Mutual exclusion.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Distributed Mutual Exclusion
Concurrency, Mutual Exclusion and Synchronization.
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
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.
1 Concurrency: Mutual Exclusion and Synchronization Module 2.2.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
DISTRIBUTED ALGORITHMS AND SYSTEMS Spring 2014 Prof. Jennifer Welch CSCE
Mutual Exclusion Using Atomic Registers Lecturer: Netanel Dahan Instructor: Prof. Yehuda Afek B.Sc. Seminar on Distributed Computation Tel-Aviv University.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
1 Shared Memory. 2 processes 3 Types of Shared Variables Read/Write Test & Set Read-Modify-Write.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
Physical clock synchronization Question 1. Why is physical clock synchronization important? Question 2. With the price of atomic clocks or GPS coming down,
CPSC 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Fall 2011 Prof. Jennifer Welch CSCE 668 Set 6: Mutual Exclusion in Shared Memory 1.
Decentralized solution 1
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.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
CSC 8420 Advanced Operating Systems Georgia State University Yi Pan Transactions are communications with ACID property: Atomicity: all or nothing Consistency:
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Background on the need for Synchronization
Introduction to Operating Systems
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Lecture 22 Syed Mansoor Sarwar
The Critical-Section Problem
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Mutual Exclusion Problem Specifications
Outline Distributed Mutual Exclusion Introduction Performance measures
Lecture 2 Part 2 Process Synchronization
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
Concurrency: Mutual Exclusion and Process Synchronization
Multiprocessor Synchronization Algorithms ( )
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
Distributed Mutual eXclusion
Syllabus 1. Introduction - History; Views; Concepts; Structure
Presentation transcript:

CS 603 Process Synchronization: The Colored Ticket Algorithm February 13, 2002

Resource Sharing Problem k identical resources, only one process can use a resource at a time Also referred to as critical section –Each process has critical section Exclusion Property: At most k processes can be in their critical section at the same time Impossibility of Deadlock: Processes eventually succeed in entering and leaving critical section Full use: All k can be used simultaneously: –If fewer than k processes in their critical section, another should be able to enter its critical section before others exit theirs

Naïve Solutions Global Semaphore –Keeps count –Doesnt prevent starvation –No notion of fairness Reduce to single resource problem –Grocery store solution: choose your line –Doesnt satisfy full use –Failure can cause starvation

Fault tolerance Fail-stop model: Process takes no more steps, unannounced –Cant use timeout to tell failed from slow If failed process causes any live process to deadlock/starve/etc., system is deemed to have failed –Failure while in critical section can tie up one resource Must be careful with definition of fair –E.g. Distinction between enter critical section and enabled to enter critical section

Colored Ticket Algorithm Assumption: N processors, fixed k resources Meets exclusion, deadlock, starvation, fairness properties –Simulates a queue (FIFO) –Robust: Failure between requesting resource and releasing resource ties up one resource Other failures have no effect Uses O(N 2 ) shared memory –Distributed virtual memory solutions can implement this Optimal in space requirements –Lower bound Ω(N 2 ) for robust algorithm to simulate queue

Queue Algorithm Meets all properties –Guarantees exclusion –Fair (FIFO) –No starvation –Robust Problem: Distributed implementation of Queue –True shared memory gives single point of failure –Distributed implementation requires substantial space repeat forever start; ENQUEUE(i) wait until i is in one of the first k positions of QUEUE; finish; { Critical Section } start; REMOVE(i); finish; { Remainder Section } end repeat.

Ticket Algorithms Idea: Take ticket when you want a resource –Ticket shows your place in line –If resources available, ticket is valid When done with resource, validate next ticket Numbered ticket: –Two shared variables –TAKE: ISSUE++ –VALIDATE: VALID++ –IS-VALID: VALID ticket Requires infinite space! local variable TICKET; repeat forever start; TICKET := TAKE-NEXT- TICKET; wait until IS-VALID(TICKET); finish; { Critical Section } start; VALIDATE-NEXT- TICKET(TICKET); finish; { Remainder Section }; end repeat.

Colored Ticket Key: Not more than N outstanding tickets –Arithmetic mod N gives bounded space –Really only need M 1+max(k, N-k) Separate into all in use and not all in use Can determine if all resources in use with three variables –B = ( VALID/M = ISSUE/M ) –V = VALID mod M –I = ISSUE mod M –If B then unused if VI else unused if V<I

Colored Ticket: Simulate Numbered Ticket Divide tickets into blocks –B true iff VALID and ISSUE in same block –V (I) gives position of VALID (ISSUE) in block Replace numbered ticket by colored tickets –T = (t, c); 0 t M-1; c is block –B := VALID.c = ISSUE.c –V := VALID.t –I := ISSUE.t function LEADS(A,B): Boolean { if A.COLOR = B.COLOR return (A.VALUE B.VALUE) else return (A.VALUE < B.VALUE) } function IS-VALID(T): Boolean { if T.COLOR = VALID.COLOR return (T.VALUE VALID.VALUE) else if T.COLOR = ISSUE.COLOR return LEADS(VALID, ISSUE) else return true; }

Colored Ticket: Bounding colors Problem: Unbounded number of colors Solution: At most k+1 colors in use –At most k tickets valid –At most (N-k) waiting But these are consecutive! Thus all will fit in one block

Colored Ticket Algorithm constant M = 1 + max(k, N - k) global variable ISSUE = (0, 0), VALID = (k, 0); Global variable QUANT[k+1] = 0; function TAKE-NEXT-TICKET: ticket { if (ISSUE.VALUE < M – 1) ISSUE.VALUE++ else { ISSUE.VALUE = 0; if LEADS(ISSUE, VALID) then ISSUE.COLOR = NEW-COLOR Else ISSUE.COLOR = VALID.COLOR, } return ISSUE; } procedure VALIDATE-NEXT-TICKET (T) { if (VALID.VALUE < M – 1) VALID.VALUE++ else { VALID.VALUE = 0; if LEADS(VALID, ISSUE) VALID.COLOR = NEW-COLOR; Else VALID.COLOR = ISSUE.COLOR; } QUANT(VALID.COLOR)++; QUANT(T.COLOR)--; } function NEW-COLOR: integer { local variable C = 0; while QUANT[C] > 0 do C++; return C }

Colored Ticket Algorithm: Space Requirements ISSUE, VALID: Range 0..M –M bounded by N QUANT: k variables range 0..M Copies maintained at every site –Guarantees robustness –Various Distributed Shared Memory protocols guarantee consistency Gives total space of O(N 2 ) –Remember that k is constant Paper gives lower bound proof