Multiprocessor Synchronization Algorithms ( )

Slides:



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

CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 6 Instructor: Haifeng YU.
Lecture 8: Three-Level Architectures CS 344R: Robotics Benjamin Kuipers.
Synchronization Algorithms and Concurrent Programming
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
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.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
Monitors & Blocking Synchronization 1. Producers & Consumers Problem Two threads that communicate through a shared FIFO queue. These two threads can’t.
Outline. Theorem For the two processor network, Bit C(Leader) = Bit C(MaxF) = 2[log 2 ((M + 2)/3.5)] and Bit C t (Leader) = Bit C t (MaxF) = 2[log 2 ((M.
Chapter 3 The Critical Section Problem
SPL/2010 Liveness And Performance 1. SPL/2010 Performance ● Throughput - How much work can your program complete in a given time unit? ● Example: HTTP.
1 Lecture 1 Distributed Algorithms Gadi Taubenfeld © 2011 Distributed Algorithms Gadi Taubenfeld Lecture 1 INTRODUCTION.
CPSC 668Set 9: Fault Tolerant Consensus1 CPSC 668 Distributed Algorithms and Systems Fall 2006 Prof. Jennifer Welch.
CPSC 668Set 9: Fault Tolerant Consensus1 CPSC 668 Distributed Algorithms and Systems Spring 2008 Prof. Jennifer Welch.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Concurrency CS 510: Programming Languages David Walker.
Multiprocess Synchronization Algorithms ( ) Lecturer: Danny Hendler.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
Concurrency Recitation – 2/24 Nisarg Raval Slides by Prof. Landon Cox.
9/8/2015cse synchronization-p1 © Perkins DW Johnson and University of Washington1 Synchronization Part 1 CSE 410, Spring 2008 Computer Systems.
1 Lecture 9: Synchronization  concurrency examples and the need for synchronization  definition of mutual exclusion (MX)  programming solutions for.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Probabilistic Methods in Concurrency Lecture 4 Problems in distributed systems for which only randomized solutions exist Catuscia Palamidessi
Consensus and Its Impossibility in Asynchronous Systems.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
1 Chapter 10 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2014 Synchronization Algorithms and Concurrent Programming Synchronization.
Mutual Exclusion Using Atomic Registers Lecturer: Netanel Dahan Instructor: Prof. Yehuda Afek B.Sc. Seminar on Distributed Computation Tel-Aviv University.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
1 Fault tolerance in distributed systems n Motivation n robust and stabilizing algorithms n failure models n robust algorithms u decision problems u impossibility.
CS 425/ECE 428 Distributed Systems Nitin Vaidya. T.A.s – Persia Aziz – Frederick Douglas – Su Du – Yixiao Lin.
CGS 3763 Operating Systems Concepts Spring 2013 Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM.
DISTRIBUTED ALGORITHMS Spring 2014 Prof. Jennifer Welch Set 9: Fault Tolerant Consensus 1.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Agenda  Quick Review  Finish Introduction  Java Threads.
Semaphores Chapter 6. Semaphores are a simple, but successful and widely used, construct.
Introduction to distributed systems description relation to practice variables and communication primitives instructions states, actions and programs synchrony.
CS3771 Today: Distributed Coordination  Previous class: Distributed File Systems Issues: Naming Strategies: Absolute Names, Mount Points (logical connection.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
The consensus problem in distributed systems
CSE 486/586 Distributed Systems Leader Election
G.Anuradha Reference: William Stallings
COMPSCI210 Recitation 12 Oct 2012 Vamsi Thummala
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Challenges in Concurrent Computing
Race Conditions Critical Sections Dekker’s Algorithm
Multiprocessor Synchronization Algorithms ( )
Designing Parallel Algorithms (Synchronization)
Distributed Consensus
Parallel and Distributed Algorithms
Distributed Consensus
Liveness And Performance
COMP60621 Fundamentals of Parallel and Distributed Systems
Semaphores Chapter 6.
Concurrency: Mutual Exclusion and Process Synchronization
Distributed Computing:
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Course Syllabus 1. Introduction - History; Views; Concepts; Structure
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Lecture 1: Introduction
Lecture 20: Synchronization
COMP60611 Fundamentals of Parallel and Distributed Systems
Distributed Mutual eXclusion
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

Multiprocessor Synchronization Algorithms (20225241) Lecturer: Danny Hendler

Electronic submissions only!!! Grade structure 3 (theoretic) problem sets Must submit all 3 Weight 30% of final grade (10% each) Take-home final exam 70% of final grade Electronic submissions only!!!

Adminstrative details Office: Alon 218 Office hours: Wednesdays, 11-13 Or schedule an appointment Course site: http://www.cs.bgu.ac.il/~msa171/ (or simply access through my home page)

Books Distributed Computing: Fundamentals, Simulations, and Advanced Topics, Hagit Attiya and Jennifer Welch, John Wiley and Sons The Art of Multiprocessor Programming Maurice Herlihy and Nir Shavit Synchronization Algorithms and Concurrent Programming, Gadi Taubenfeld, Pearson/Prentice Hall. Book site: http://www.faculty.idc.ac.il/gadi/book.htm

5

Moore’s law Exponential growth in computing power 6 6

The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun (RIP), AMD, IBM now focusing on “multi- core” architectures Soon, most desktops will be multiprocessors 7

The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun (RIP), AMD, IBM now focusing on “multi- core” architectures Soon, most desktops will be multiprocessors Soon, most laptops will be multiprocessors 8

The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun (RIP), AMD, IBM now focusing on “multi- core” architectures Soon, most desktops will be multiprocessors Soon, most laptops will be multiprocessors Soon, most cellular phonse will contain multiprocessors 9

The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun (RIP), AMD, IBM now focusing on “multi- core” architectures Soon, most desktops will be multiprocessors Soon, most laptops will be multiprocessors Soon, most cellular phonse will contain multiprocessors Soon, most TVs will contain multiprocessors 10

The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun (RIP), AMD, IBM now focusing on “multi- core” architectures Soon, most desktops will be multiprocessors Soon, most laptops will be multiprocessors Soon, most cellular phonse will contain multiprocessors Soon, most TVs will contain multiprocessors Soon, most cars will contain multiprocessors 11

How can we write correct and efficient algorithms for multiprocessors? The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun (RIP), AMD, IBM now focusing on “multi- core” architectures Soon, most desktops will be multiprocessors Soon, most laptops will be multiprocessors Soon, most cellular phonse will contain multiprocessors Soon, most TVs will contain multiprocessors Soon, most cars will contain multiprocessors How can we write correct and efficient algorithms for multiprocessors? 12

Distributed Systems The Internet A distributed system is a collection of individual computing devices that communicate with one another. E.g.: VLSI chips Shared-memory multiprocessor Local-area network The Internet

One sequential model, MANY distributed models Shared-memory / Message-passing Which operations are allowed (read, write, read-modify-write)? Synchronous, timing-conditions, asynchronous Are failures allowed? Fail-stop, Byzantine failures, message omission Is the number of processes known?

Motivating examples of Synchronization

The Too-Much-Milk Problem Time Alice Bob 5:00 Arrive Home 5:05 Look in fridge; no milk 5:10 Leave for grocery 5:15 Arrive home 5:20 Arrive at grocery 5:25 Buy milk 5:30 Arrive home; put milk in fridge 5:40 5:45 Arrive home; too much milk! Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solving the Too-Much-Milk Problem Required properties Mutual Exclusion: Only one person checks&buys milk “at a time” Progress: Someone always buys milk if it is needed Communication primitives Leave a note (set a flag) Remove a note (reset a flag) Read a note (test the flag) Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Important Distinction Safety Property Nothing bad ever happens Example: mutual exclusion Liveness Property Something good happens eventually Example: progress Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solution 1 Alice if (no milk) { if (no note) { leave note buy milk remove note } Bob Does it work? No, may end up with “two milk”. mutual exclusion progress Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solution 2 Using labeled notes Alice leave note A if (no note B) { if (no milk) {buy milk} } remove note A Bob leave note B if (no note A) { remove note B No, may end up with no milk. mutual exclusion progress Does it work? Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solution 3 Alice leave note A while (note B) {skip} if (no milk) {buy milk} remove note A Bob leave note B if (no note A) { } remove note B Does it work? mutual exclusion progress Only if we make a timing assumption! (So, no.) Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Is solution #3 a good solution? No A timing assumption is needed! Unfair to one of the processes Alice is busy waiting – consuming CPU cycles without accomplishing useful work Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solution 4 Using 4 labeled notes A1 A2 B2 B1 the fridge’s door Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solution 4 Alice leave A1 if B2 {leave A2} else {remove A2} while B1 and ((A2 and B2) or (no A2 and no B2)) {skip} if (no milk) {buy milk} remove A1 Bob leave B1 if (no A2) {leave B2} else {remove B2} while A1 and ((A2 and no B2) or (no A2 and B2)) remove B1 A correct, fair, symmetric algorithm! (surprisingly complicated, though) Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solution 4 Notations solid line without color: we do not care if there is a note color: there is a note dotted line: there is no note A1 A2 X B2 X B2 Alice’s turn who will buy milk ? Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

Solution 4 A1 A2 X B2 X B2 A1 A2 B2 B1 A1 A2 B2 B1 Alice’s turn These should be interpreted as follows: if the participant (Alice/Bob) evaluates the waiting condition and finds out that the condition depicted in the box is met – it can safely buy milk if there is none. Intuition regarding algorithm’s correctness. (Formal proofs provided later in the course.) Mutual exclusion: Assume towards a contradiction that (WLOG) Alice enters CS and then Bob. If Bob before second statement when Alice enters, clearly it may not enter also, since when it evaluates the while condition – the two sub-conditions hold. So it must be that when Alice enters, Bob already executed its first two statements. Since Alice enters, she observed asymmetry between A2, B2, hence Bob will also observe this asymmetry and will not be able to enter. Deadlock freedom: either there is symmetry or asymmetry between A2, B2, so it can’t be that both Alice and Bob are stuck. Starvation freedom – Assume there is starvation, then (WLOG) Alice is stuck and Bob keeps on getting in. In the second time it does while Alice is waiting, Bob’s execution of the second statement will free Alice. Bob’s turn Bob’s turn Bob’s turn Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

A variant of Solution 4 The order of the first two statements is replaced Is it correct ? Alice if B2 {leave A2} else {remove A2} leave A1 while B1 and ((A2 and B2) or (no A2 and no B2)) {skip} if (no milk) {buy milk} remove A1 Bob if (no A2) {leave B2} else {remove B2} leave B1 while A1 and ((A2 and no B2) or (no A2 and B2)) remove B1 No, may end up with two milk. B2 A1 B2 B2 B2 B2 B1 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

A variant of Solution 4 The order of the first two statements is replaced Is it correct ? Alice if B2 {leave A2} else {remove A2} leave A1 while B1 and ((A2 and B2) or (no A2 and no B2)) {skip} if (no milk) {buy milk} remove A1 Bob if (no A2) {leave B2} else {remove B2} leave B1 while A1 and ((A2 and no B2) or (no A2 and B2)) remove B1 MILK No, may end up with two milk. B2 A1 B2 B2 B2 B1 B2 mutual exclusion progress Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

The coordinated attack problem Blue army wins if both blue camps attack simultaneously Design an algorithm to ensure that both blue camps attack simultaneously Left blue general is leader, will decide on time and notify Enemy 1 2 The problem is due to Jim Gray (1977) Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

The coordinated attack problem Communication is done by sending messengers across valley Messengers may be lost or captured by the enemy  When successful, it takes a messenger one hour to arrive We seek a deterministic solution Enemy 1 2 Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006

The coordinated attack problem (a.k.a. the Two General’s problem) Theorem: There is no algorithm that solves this problem! Proof (informal): Assume to the contrary that such an algorithm exists. Let P be an algorithm that solves it with the fewest # of messages, when no message is lost. P should work even when the last messenger is captured. So P should work even if the last messenger is never sent. So there is a correct algorithm P’ that sends one message less. A contradiction.  The model is too weak for solving this problem! Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006