Multiprocessor Synchronization Algorithms 20225241 Lecturer Danny Hendler Grade

  • Slides: 25
Download presentation
Multiprocessor Synchronization Algorithms (20225241) Lecturer: Danny Hendler

Multiprocessor Synchronization Algorithms (20225241) Lecturer: Danny Hendler

Grade structure • 3 (theoretic) problem sets – Up to 30% of grade •

Grade structure • 3 (theoretic) problem sets – Up to 30% of grade • Take-home final exam – At least 70% of grade Electronic submissions only!!! 2

Adminstrative details - Office: Alon 218 - Office hours: - Mondays, 2 pm-4 pm

Adminstrative details - Office: Alon 218 - Office hours: - Mondays, 2 pm-4 pm - Or make an appointment - Course site: http: //www. cs. bgu. ac. il/academics/courses/2009/a/220225401 (or simply enter through my home page) 3

Books • Distributed Computing: Fundamentals, Simulations, and Advanced Topics, Hagit Attiya and Jennifer Welch,

Books • Distributed Computing: Fundamentals, Simulations, and Advanced Topics, Hagit Attiya and Jennifer Welch, John Wiley and Sons • Synchronization Algorithms and Concurrent Programming, Gadi Taubenfeld, Pearson/Prentice Hall. Book site: http: //www. faculty. idc. ac. il/gadi/book. htm 4

5

5

Moore’s law Exponential growth in computing power 6

Moore’s law Exponential growth in computing power 6

The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun, AMD,

The Future of Computing Speeding up uni-processors is harder and harder Intel, Sun, AMD, IBM now focusing on “multicore” architectures Soon, most computers will be multiprocessors How can we write correct and efficient algorithms for multiprocessors? 7

Distributed Systems • A distributed system is a collection of individual computing devices that

Distributed Systems • 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 8

One sequential model, MANY distributed models • Shared-memory / Message-passing – Which operations are

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

Types of distributed systems • • Multi-core computers The Internet Peer-to-peer systems Grid computers

Types of distributed systems • • Multi-core computers The Internet Peer-to-peer systems Grid computers Wireless networks Sensor networks Ad-hoc networks … 10

Motivating examples of Synchronization 11

Motivating examples of Synchronization 11

The Too-Much-Milk Problem Time Alice 5: 00 Arrive Home 5: 05 Look in fridge;

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

Solving the Too-Much-Milk Problem Required properties q Mutual Exclusion: Only one person buys milk

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

Important Distinction q Safety Property – Nothing bad ever happens – Example: mutual exclusion

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

Solution 1 Alice if (no milk) { if (no note) { leave Note buy

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

Solution 2 Using labeled notes Alice leave note A if (no note B) {

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

Solution 3 Alice leave note A while (note B) {skip} if (no milk) {buy

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) { if (no milk) {buy milk} } remove note B Does it work? Only if we make a timing assumption! ümutual exclusion C progress Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006 17

Solution 4 Using 4 labeled notes A 1 A 2 B 1 the fridge’s

Solution 4 Using 4 labeled notes A 1 A 2 B 1 the fridge’s door Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006 19

Solution 4 Alice leave A 1 if B 2 {leave A 2} else {remove

Solution 4 Alice leave A 1 if B 2 {leave A 2} else {remove A 2} while B 1 and ((A 2 and B 2) or (no A 2 and no B 2)) {skip} if (no milk) {buy milk} remove A 1 Bob leave B 1 if (no A 2) {leave B 2} else {remove B 2} while A 1 and ((A 2 and no B 2) or (no A 2 and B 2)) {skip} if (no milk) {buy milk} remove B 1 A correct, fair, symmetric algorithm! Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006 20

Solution 4 A 1 A 2 X B 2 Alice’s turn B 2 A

Solution 4 A 1 A 2 X B 2 Alice’s turn B 2 A 2 X B 1 Bob’s turn A 1 A 2 B 2 B 1 Alice’s turn A 1 A 2 B 2 B 1 Bob’s turn Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006 22

A variant of Solution 4 The order of the first two statements is replaced

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

A variant of Solution 4 The order of the first two statements is replaced

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

The coordinated attack problem • Blue army wins if both blue camps attack simultaneously

The coordinated attack problem • Blue army wins if both blue camps attack simultaneously • Design an algorithm to ensure that both blue camps attack simultaneously 1 2 Enemy The problem is due to by Jim Gray (1977) Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006 25

The coordinated attack problem • Communication is done by sending messengers across valley •

The coordinated attack problem • Communication is done by sending messengers across valley • Messengers may be lost or captured by the enemy 1 2 Enemy Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006 26

The coordinated attack problem Theorem: There is no algorithm that solves this problem !

The coordinated attack problem Theorem: There is no algorithm that solves this problem ! Proof: • Assume to the contrary that such an algorithm exits. • 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. • But this is a new algorithm with one less message. • A contradiction. The model is too weak! Synchronization Algorithms and Concurrent Programming Gadi Taubenfeld © 2006 27