Peterson s Algorithm
|
|
- Prudence Flynn
- 5 years ago
- Views:
Transcription
1 Peterson s Algorithm public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {}; } public void unlock() { flag[i] = false; } 24/03/10 Art of Multiprocessor Programming 1
2 Mutual Exclusion public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {}; If thread 0 in critical section, flag[0]=true, victim = 1 If thread 1 in critical section, flag[1]=true, victim = 0 Cannot both be true 24/03/10 Art of Multiprocessor Programming 2
3 Deadlock Free public void lock() { while (flag[j] && victim == i) {}; Thread blocked only at while loop only if it is the victim One or the other must not be the victim 24/03/10 Art of Multiprocessor Programming 3
4 Starvation Free Thread i blocked only if j repeatedly re-enters so that flag[j] == true and victim == i When j re-enters it sets victim to j. So i gets in public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {}; } public void unlock() { flag[i] = false; } 24/03/10 Art of Multiprocessor Programming 4
5 The Filter Algorithm for n Threads There are n-1 waiting rooms called levels At each level At least one enters level At least one blocked if many try ncs cs Only one thread makes it through 24/03/10 Art of Multiprocessor Programming 5
6 Filter class Filter implements Lock { volatile int[] level; // level[i] for thread i volatile int[] victim; // victim[l] for level L } public Filter(int n) { level = new int[n]; victim = new int[n]; level for (int i = 1; i < n; i++) { level[i] = 0; }} 0 2 n Thread 2 at level 4 24/03/10 Art of Multiprocessor Programming 6 n-1 victim
7 Filter class Filter implements Lock { public void lock(){ for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i level[k] >= L) && victim[l] == i ); }} public void unlock() { level[i] = 0; }} 24/03/10 Art of Multiprocessor Programming 7
8 Filter class Filter implements Lock { public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i) level[k] >= L) && victim[l] == i); }} public void release(int i) { level[i] = 0; }} One level at a time 24/03/10 Art of Multiprocessor Programming 8
9 Filter class Filter implements Lock { public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i) level[k] >= L) && victim[l] == i); // busy wait }} public void release(int i) { level[i] = 0; }} Announce intention to enter level L 24/03/10 Art of Multiprocessor Programming 9
10 Filter class Filter implements Lock { int level[n]; int victim[n]; public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i) level[k] >= L) && victim[l] == i); }} public void release(int i) { level[i] = 0; }} Give priority to anyone but me 24/03/10 Art of Multiprocessor Programming 10
11 Filter class Filter implements Lock { int level[n]; int victim[n]; public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; Wait as long as someone else is at same or higher level, and I m designated victim while (( k!= i) level[k] >= L) && victim[l] == i); }} public void release(int i) { level[i] = 0; }} 24/03/10 Art of Multiprocessor Programming 11
12 Filter class Filter implements Lock { int level[n]; int victim[n]; public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i) level[k] >= L) && victim[l] == i); }} public void release(int i) { level[i] = 0; }} Thread enters level L when it completes the loop 24/03/10 Art of Multiprocessor Programming 12
13 Claim Start at level L=0 At most n-l threads enter level L Mutual exclusion at level L=n-1 ncs L=0 L=1 L=n-2 cs L=n-1 24/03/10 Art of Multiprocessor Programming 13
14 Induction Hypothesis No more than n-l+1 at level L-1 Induction step: by contradiction Assume all at level L-1 enter level L A last to write victim[l] B is any other thread at level L ncs cs assume L-1 has n-l+1 L has n-l prove 24/03/10 Art of Multiprocessor Programming 14
15 Proof Structure Last to write victim[l] A ncs cs B Assumed to enter L-1 n-l+1 = 4 n-l+1 = 4 By way of contradiction all enter L Show that A must have seen B at level L and since victim[l] == A could not have entered 24/03/10 Art of Multiprocessor Programming 15
16 From the Code (1) write B (level[b]=l)write B (victim[l]=b) public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i) level[k] >= L) && victim[l] == i) {}; }} 24/03/10 Art of Multiprocessor Programming 16
17 From the Code (2) write A (victim[l]=a)read A (level[b]) public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i) level[k] >= L) && victim[l] == i) {}; }} 24/03/10 Art of Multiprocessor Programming 17
18 By Assumption (3) write B (victim[l]=b)write A (victim[l]=a) By assumption, A is the last thread to write victim[l] 24/03/10 Art of Multiprocessor Programming 18
19 Combining Observations (1) write B (level[b]=l)write B (victim[l]=b) (3) write B (victim[l]=b)write A (victim[l]=a) (2) write A (victim[l]=a)read A (level[b]) 24/03/10 Art of Multiprocessor Programming 19
20 Combining Observations (1) write B (level[b]=l)write B (victim[l]=b) (3) write B (victim[l]=b)write A (victim[l]=a) (2) write A (victim[l]=a)read A (level[b]) 24/03/10 public void lock() { for (int L = 1; L < n; L++) { level[i] = L; victim[l] = i; while (( k!= i) level[k] >= L) && victim[l] == i) {}; }} Art of Multiprocessor Programming 20
21 Combining Observations (1) write B (level[b]=l)write B (victim[l]=b) (3) write B (victim[l]=b)write A (victim[l]=a) (2) write A (victim[l]=a)read A (level[b]) Thus, A read level[b] L, A was last to write victim[l], so it could not have entered level L! 24/03/10 Art of Multiprocessor Programming 21
22 No Starvation Filter Lock satisfies properties: Just like Peterson Alg at any level So no one starves But what about fairness? Threads can be overtaken by others 24/03/10 Art of Multiprocessor Programming 22
23 Bounded Waiting Want stronger fairness guarantees Thread not overtaken too much Need to adjust definitions. 24/03/10 Art of Multiprocessor Programming 23
24 Bounded Waiting Divide lock() method into 2 parts: Doorway interval: Written DA always finishes in finite steps Waiting interval: Written WA may take unbounded steps 24/03/10 Art of Multiprocessor Programming 24
25 r-bounded Waiting For threads A and B: If D A k D B j A s k-th doorway precedes B s j-th doorway Then CS A k CS B j+r A s k-th critical section precedes B s (j+r)-th critical section B cannot overtake A by more than r times First-come-first-served means r = 0. 24/03/10 Art of Multiprocessor Programming 25
26 Fairness Again Filter Lock satisfies properties: No one starves But very weak fairness Not r-bounded for any r! That s pretty lame 24/03/10 Art of Multiprocessor Programming 26
27 Bakery Algorithm Provides First-Come-First-Served How? Take a number Wait until lower numbers have been served Lexicographic order (a,i) > (b,j) If a > b, or a = b and i > j 24/03/10 Art of Multiprocessor Programming 27
28 Bakery Algorithm class Bakery implements Lock { } volatile boolean[] flag; volatile Label[] label; public Bakery (int n) { flag = new boolean[n]; label = new Label[n]; for (int i = 0; i < n; i++) { } flag[i] = false; label[i] = 0; 24/03/10 Art of Multiprocessor Programming 28
29 Bakery Algorithm class Bakery implements Lock { } volatile boolean[] flag; volatile Label[] label; public Bakery (int n) { flag = new boolean[n]; f f t f f t f f label = new Label[n]; for (int i = 0; i < n; i++) { } flag[i] = false; label[i] = 0; 0 2 CS 6 n-1 24/03/10 Art of Multiprocessor Programming 29
30 Bakery Algorithm class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } 24/03/10 Art of Multiprocessor Programming 30
31 Bakery Algorithm class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; Doorway while ( k flag[k] && (label[i],i) > (label[k],k)); } 24/03/10 Art of Multiprocessor Programming 31
32 Bakery Algorithm class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; I m interested while ( k flag[k] && (label[i],i) > (label[k],k)); } 24/03/10 Art of Multiprocessor Programming 32
33 Bakery Algorithm class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } Take increasing label (read labels in some arbitrary order) 24/03/10 Art of Multiprocessor Programming 33
34 Bakery Algorithm class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } Someone is interested 24/03/10 Art of Multiprocessor Programming 34
35 Bakery Algorithm class Bakery implements Lock { boolean flag[n]; int label[n]; Someone is interested public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } With lower (label,i) in lexicographic order 24/03/10 Art of Multiprocessor Programming 35
36 Bakery Algorithm class Bakery implements Lock { public void unlock() { flag[i] = false; } } 24/03/10 Art of Multiprocessor Programming 36
37 Bakery Algorithm class Bakery implements Lock { No longer interested public void unlock() { flag[i] = false; } } labels are always increasing 24/03/10 Art of Multiprocessor Programming 37
38 No Deadlock There is always one thread with earliest label Ties are impossible (why?) 24/03/10 Art of Multiprocessor Programming 38
39 First-Come-First-Served If DA D B then A s label is earlier write A (label[a]) read B (label[a]) write B (label[b]) read B (flag[a]) So B is locked out while flag[a] is true class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } 24/03/10 Art of Multiprocessor Programming 39
40 Mutual Exclusion Suppose A and B in CS together Suppose A has earlier label When B entered, it must have seen flag[a] is false, or label[a] > label[b] class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } 24/03/10 Art of Multiprocessor Programming 40
41 Mutual Exclusion Labels are strictly increasing so B must have seen flag[a] == false 24/03/10 Art of Multiprocessor Programming 41
42 Mutual Exclusion Labels are strictly increasing so B must have seen flag[a] == false Labeling B read B (flag[a]) write A (flag[a]) Labeling A 24/03/10 Art of Multiprocessor Programming 42
43 Mutual Exclusion Labels are strictly increasing so B must have seen flag[a] == false Labeling B read B (flag[a]) write A (flag[a]) Labeling A Which contradicts the assumption that A has an earlier label 24/03/10 Art of Multiprocessor Programming 43
44 Bakery Y2 32 K Bug class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } 24/03/10 Art of Multiprocessor Programming 44
45 Bakery Y2 32 K Bug class Bakery implements Lock { public void lock() { flag[i] = true; label[i] = max(label[0],,label[n-1])+1; while ( k flag[k] && (label[i],i) > (label[k],k)); } Mutex breaks if label[i] overflows 24/03/10 Art of Multiprocessor Programming 45
46 Deep Philosophical Question The Bakery Algorithm is Succinct, Elegant, and Fair. Q: So why isn t it practical? A: Well, you have to read N distinct variables 24/03/10 Art of Multiprocessor Programming 46
47 Shared Memory Shared read/write memory locations called Registers (historical reasons) Come in different flavors Multi-Reader-Single-Writer (Flag[]) Multi-Reader-Multi-Writer (Victim[]) Not interesting: SRMW and SRSW 24/03/10 Art of Multiprocessor Programming 47
48 Theorem At least N MRSW (multi-reader/singlewriter) registers are needed to solve deadlock-free mutual exclusion. N registers like Flag[] 24/03/10 Art of Multiprocessor Programming 48
49 Proving Algorithmic Impossibility C To show no algorithm exists: assume by way of contradiction one does, show a bad execution that violates properties: in our case assume an alg for deadlock free mutual exclusion using < N registers write CS 24/03/10 Art of Multiprocessor Programming 49
50 Proof: Need N-MRSW Registers Each thread must write to some register A B C write write CS CS CS can t tell whether A is in critical section 24/03/10 Art of Multiprocessor Programming 50
51 Upper Bound Bakery algorithm Uses 2N MRSW registers So the bound is (pretty) tight But what if we use MRMW registers? Like victim[]? 24/03/10 Art of Multiprocessor Programming 51
52 Bad News Theorem At least N MRMW multireader/multi-writer registers are needed to solve deadlock-free mutual exclusion. (So multiple writers don t help) 24/03/10 Art of Multiprocessor Programming 52
53 Theorem (First 2-Threads) Theorem: Deadlock-free mutual exclusion for 2 threads requires at least 2 multi-reader multi-writer registers Proof: assume one register suffices and derive a contradiction 24/03/10 Art of Multiprocessor Programming 53
54 Two Thread Execution A B Write(R) R CS CS Threads run, reading and writing R Deadlock free so at least one gets in 24/03/10 Art of Multiprocessor Programming 54
55 Covering State for One Register B Write(R) B has to write to the register before entering CS, so stop it just before 24/03/10 Art of Multiprocessor Programming 55
56 Proof: Assume Cover of 1 A B Write(R) CS A runs, possibly writes to the register, enters CS 24/03/10 Art of Multiprocessor Programming 56
57 Proof: Assume Cover of 1 A B CS B Runs, first obliterating any trace of A, then also enters the critical section Write(R) CS 24/03/10 Art of Multiprocessor Programming 57
58 Theorem Deadlock-free mutual exclusion for 3 threads requires at least 3 multireader multi-writer registers 24/03/10 Art of Multiprocessor Programming 58
59 Proof: Assume Cover of 2 A B C Write(R B ) Write(R C ) Only 2 registers 24/03/10 Art of Multiprocessor Programming 59
60 Run A Solo A B C Write(R B ) Write(R C ) CS Writes to one or both registers, enters CS 24/03/10 Art of Multiprocessor Programming 60
61 Obliterate Traces of A A B C Write(R B ) Write(R C ) CS Other threads obliterate evidence that A entered CS 24/03/10 Art of Multiprocessor Programming 61
62 Mutual Exclusion Fails A B C Write(R B ) Write(R C ) CS CS CS looks empty, so another thread gets in 24/03/10 Art of Multiprocessor Programming 62
63 Proof Strategy Proved: a contradiction starting from a covering state for 2 registers Claim: a covering state for 2 registers is reachable from any state where CS is empty 24/03/10 Art of Multiprocessor Programming 63
64 Covering State for Two A B Write(R A ) Write(R B ) If we run B through CS 3 times, B must return twice to cover some register, say R B 24/03/10 Art of Multiprocessor Programming 64
65 Covering State for Two A B Write(R A ) Write(R B ) Start with B covering register RB for the 1 st time Run A until it is about to write to uncovered RA Are we done? 24/03/10 Art of Multiprocessor Programming 65
66 Covering State for Two A B Write(R A ) Write(R B ) NO! A could have written to R B So CS no longer looks empty 24/03/10 Art of Multiprocessor Programming 66
67 Covering State for Two A B Write(R A ) Write(R B ) Run B obliterating traces of A in RB Run B again until it is about to write to RB Now we are done 24/03/10 Art of Multiprocessor Programming 67
68 Inductively We Can Show A B C Write(R A ) Write(R B ) Write(R C ) There is a covering state Where k threads not in CS cover k distinct registers Proof follows when k = N-1 24/03/10 Art of Multiprocessor Programming 68
69 Summary of Lecture In the 1960 s many incorrect solutions to starvation-free mutual exclusion using RW-registers were published Today we know how to solve FIFO N thread mutual exclusion using 2N RW- Registers 24/03/10 Art of Multiprocessor Programming 69
70 Summary of Lecture N RW-Registers inefficient Because writes cover older writes Need stronger hardware operations do not have the covering problem In next lectures - understand what these operations are 24/03/10 Art of Multiprocessor Programming 70
71 This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. You are free: to Share to copy, distribute and transmit the work to Remix to adapt the work Under the following conditions: Attribution. You must attribute the work to The Art of Multiprocessor Programming (but not in any way that suggests that the authors endorse you or your use of the work). Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license. For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to Any of the above conditions can be waived if you get permission from the copyright holder. Nothing in this license impairs or restricts the author's moral rights. 24/03/10 Art of Multiprocessor Programming 71
Programming Paradigms for Concurrency Lecture 2 - Mutual Exclusion
Programming Paradigms for Concurrency Lecture 2 - Mutual Exclusion Based on companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Thomas Wies New York University
More informationMutual Exclusion. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Mutual Exclusion Companion slides for The by Maurice Herlihy & Nir Shavit Mutual Exclusion Today we will try to formalize our understanding of mutual exclusion We will also use the opportunity to show
More informationLecture 7: Mutual Exclusion 2/16/12. slides adapted from The Art of Multiprocessor Programming, Herlihy and Shavit
Principles of Concurrency and Parallelism Lecture 7: Mutual Exclusion 2/16/12 slides adapted from The Art of Multiprocessor Programming, Herlihy and Shavit Time Absolute, true and mathematical time, of
More informationMutual Exclusion. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Mutual Exclusion Companion slides for The by Maurice Herlihy & Nir Shavit Mutual Exclusion In his 1965 paper E. W. Dijkstra wrote: "Given in this paper is a solution to a problem which, to the knowledge
More informationWhat We'll Cover Today
Mutual Exclusion Acknowledgement: Slides adopted from the companion slides for the book "The Art of Mul>processor Programming" by Maurice Herlihy and Nir Shavit What We'll Cover Today Chapter 2 of: Digital
More informationMutual Exclusion. 1 Formal problem definitions. Time notion CSE /17/2015. Outline of this lecture:
CSE 539 03/17/2015 Mutual Exclusion Lecture 15 Scribe: Son Dinh Outline of this lecture: 1. Formal problem definitions 2. Solution for 2 threads 3. Solution for n threads 4. Inherent costs of mutual exclusion
More informationSolution: a lock (a/k/a mutex) public: virtual void unlock() =0;
1 Solution: a lock (a/k/a mutex) class BasicLock { public: virtual void lock() =0; virtual void unlock() =0; ; 2 Using a lock class Counter { public: int get_and_inc() { lock_.lock(); int old = count_;
More informationMutual Exclusion: Classical Algorithms for Locks
Mutual Exclusion: Classical Algorithms for Locks John Mellor-Crummey Department of Computer Science Rice University johnmc@cs.rice.edu COMP 422 Lecture 18 21 March 2006 Motivation Ensure that a block of
More informationDD2451 Parallel and Distributed Computing --- FDD3008 Distributed Algorithms
DD2451 Parallel and Distributed Computing --- FDD3008 Distributed Algorithms Lecture 1 Mads Dam Autumn/Winter 2011 DD2451 Overview Lectures 12 double lectures Twice a week until beg. December Focus on
More informationProgramming Paradigms for Concurrency Lecture 3 Concurrent Objects
Programming Paradigms for Concurrency Lecture 3 Concurrent Objects Based on companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified by Thomas Wies New York University
More information10/28/11. DD2451 Overview. DD2451 Overview. FDD 3008 Overview. Course Material
/8/ DD45 Parallel and Distributed omputing --- FDD38 Distributed lgorithms Lecture Mads Dam utumn/winter Lectures double lectures Twice a week until beg. December Focus on theory and principles ut look
More informationUnit 6: Indeterminate Computation
Unit 6: Indeterminate Computation Martha A. Kim October 6, 2013 Introduction Until now, we have considered parallelizations of sequential programs. The parallelizations were deemed safe if the parallel
More informationAdvanced Multiprocessor Programming
Advanced Multiprocessor Programming Jesper Larsson Träff traff@par.tuwien.ac.at Research Group Parallel Computing Faculty of Informatics, Institute of Information Systems Vienna University of Technology
More informationConcurrent Computing
Concurrent Computing Introduction SE205, P1, 2017 Administrivia Language: (fr)anglais? Lectures: Fridays (15.09-03.11), 13:30-16:45, Amphi Grenat Web page: https://se205.wp.imt.fr/ Exam: 03.11, 15:15-16:45
More informationLecture. DM510 - Operating Systems, Weekly Notes, Week 11/12, 2018
Lecture In the lecture on March 13 we will mainly discuss Chapter 6 (Process Scheduling). Examples will be be shown for the simulation of the Dining Philosopher problem, a solution with monitors will also
More informationLecture Topics. Announcements. Today: Concurrency: Mutual Exclusion (Stallings, chapter , 5.7)
Lecture Topics Today: Concurrency: Mutual Exclusion (Stallings, chapter 5.1-5.4, 5.7) Next: Concurrency: Deadlock and Starvation (Stallings, chapter 6.1, 6.6-6.8) 1 Announcements Self-Study Exercise #5
More informationChapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?
Chapter 6: Process [& Thread] Synchronization CSCI [4 6] 730 Operating Systems Synchronization Part 1 : The Basics Why is synchronization needed? Synchronization Language/Definitions:» What are race conditions?»
More informationShared-Memory Computability
Shared-Memory Computability 10011 Universal Object Wait-free/Lock-free computable = Threads with methods that solve n- consensus Art of Multiprocessor Programming Copyright Herlihy- Shavit 2007 93 GetAndSet
More informationProcess Synchronization
Process Synchronization Concurrent access to shared data may result in data inconsistency Multiple threads in a single process Maintaining data consistency requires mechanisms to ensure the orderly execution
More information! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA
Chapter 6: Process [& Thread] Synchronization CSCI [4 6] 730 Operating Systems Synchronization Part 1 : The Basics! Why is synchronization needed?! Synchronization Language/Definitions:» What are race
More informationCSCI [4 6] 730 Operating Systems. Example Execution. Process [& Thread] Synchronization. Why does cooperation require synchronization?
Process [& Thread] Synchronization CSCI [4 6] 730 Operating Systems Synchronization Part 1 : The Basics Why is synchronization needed? Synchronization Language/Definitions: What are race conditions? What
More informationPre- and post- CS protocols. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7. Other requirements for a mutual exclusion algorithm
CS 361 Concurrent programming Drexel University Fall 2004 Lecture 7 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce
More informationPart III Synchronization Software and Hardware Solutions
Part III Synchronization Software and Hardware Solutions Spring 2018 Computers are useless. They can only give answers. 1 Pablo Picasso Software Solutions for Two Processes Suppose we have two processes
More informationModels of concurrency & synchronization algorithms
Models of concurrency & synchronization algorithms Lecture 3 of TDA383/DIT390 (Concurrent Programming) Carlo A. Furia Chalmers University of Technology University of Gothenburg SP3 2016/2017 Today s menu
More informationSPIN, PETERSON AND BAKERY LOCKS
Concurrent Programs reasoning about their execution proving correctness start by considering execution sequences CS4021/4521 2018 jones@scss.tcd.ie School of Computer Science and Statistics, Trinity College
More informationProcess Synchronization. Mehdi Kargahi School of ECE University of Tehran Spring 2008
Process Synchronization Mehdi Kargahi School of ECE University of Tehran Spring 2008 Producer-Consumer (Bounded Buffer) Producer Consumer Race Condition Producer Consumer Critical Sections Structure of
More informationProcess Synchronization
CSC 4103 - Operating Systems Spring 2007 Lecture - VI Process Synchronization Tevfik Koşar Louisiana State University February 6 th, 2007 1 Roadmap Process Synchronization The Critical-Section Problem
More informationCoarse-grained and fine-grained locking Niklas Fors
Coarse-grained and fine-grained locking Niklas Fors 2013-12-05 Slides borrowed from: http://cs.brown.edu/courses/cs176course_information.shtml Art of Multiprocessor Programming 1 Topics discussed Coarse-grained
More informationSpin Locks and Contention. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Focus so far: Correctness and Progress Models Accurate (we never lied to you) But idealized
More informationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization 1 Needs of Processes Allocation of processor time Allocation and sharing resources Communication among processes Synchronization of multiple processes
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2017 Lecture 11 Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel Feedback Queue: Q0, Q1,
More informationChapter 5: Process Synchronization. Operating System Concepts Essentials 2 nd Edition
Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks
More informationAtomicity and Virtualization. Atomicity. Critical section. Edsger s perspective. Virtualizing a resource requires managing concurrent accesses
Atomicity and Virtualization Atomicity Virtualizing a resource requires managing concurrent accesses data structures must transition between consistent states atomic actions transform state indivisibly
More informationConcurrent Skip Lists. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Concurrent Skip Lists Companion slides for The by Maurice Herlihy & Nir Shavit Set Object Interface Collection of elements No duplicates Methods add() a new element remove() an element contains() if element
More informationChapter 6: Synchronization. Operating System Concepts 8 th Edition,
Chapter 6: Synchronization, Silberschatz, Galvin and Gagne 2009 Outline Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization
More informationMULTITHREADING AND SYNCHRONIZATION. CS124 Operating Systems Fall , Lecture 10
MULTITHREADING AND SYNCHRONIZATION CS124 Operating Systems Fall 2017-2018, Lecture 10 2 Critical Sections Race conditions can be avoided by preventing multiple control paths from accessing shared state
More informationSequen&al Consistency and Linearizability
Sequen&al Consistency and Linearizability (Or, Reasoning About Concurrent Objects) Acknowledgement: Slides par&ally adopted from the companion slides for the book "The Art of Mul&processor Programming"
More informationOperating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy
Operating Systems Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. AL-AZHAR University Website : eaymanelshenawy.wordpress.com Email : eaymanelshenawy@yahoo.com Reference
More informationCS 361 Concurrent programming Drexel University Fall 2004 Lecture 8. Proof by contradiction. Proof of correctness. Proof of mutual exclusion property
CS 361 Concurrent programming Drexel University Fall 2004 Lecture 8 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce
More informationExample Threads. compile: gcc mythread.cc -o mythread -lpthread What is the output of this program? #include <pthread.h> #include <stdio.
Example Threads #include #include int num = 0; void *add_one(int *thread_num) { num++; printf("thread %d num = %d\n", *thread_num, num); } void main() { pthread_t thread; int my_id
More informationChapter 5: Process Synchronization. Operating System Concepts 9 th Edition
Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks
More informationConcurrency: Mutual Exclusion and
Concurrency: Mutual Exclusion and Synchronization 1 Needs of Processes Allocation of processor time Allocation and sharing resources Communication among processes Synchronization of multiple processes
More informationChapter 6: Process Synchronization
Chapter 6: Process Synchronization Chapter 6: Synchronization 6.1 Background 6.2 The Critical-Section Problem 6.3 Peterson s Solution 6.4 Synchronization Hardware 6.5 Mutex Locks 6.6 Semaphores 6.7 Classic
More informationChapter 6: Synchronization. Chapter 6: Synchronization. 6.1 Background. Part Three - Process Coordination. Consumer. Producer. 6.
Part Three - Process Coordination Chapter 6: Synchronization 6.1 Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure
More informationSemaphores. May 10, Mutual exclusion with shared variables is difficult (e.g. Dekker s solution).
Semaphores May 10, 2000 1 Introduction Mutual exclusion with shared variables is difficult (e.g. Dekker s solution). Generalising to an arbitrary number of processes is also nontrivial (e.g. Lamport s
More informationThread Synchronization: Foundations. Properties. Safety properties. Edsger s perspective. Nothing bad happens
Edsger s perspective Testing can only prove the presence of bugs Thread Synchronization: Foundations Properties Property: a predicate that is evaluated over a run of the program (a trace) every message
More informationChapter 7: Process Synchronization. Background. Illustration
Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris
More informationOperating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017
Operating Systems Lecture 4 - Concurrency and Synchronization Adrien Krähenbühl Master of Computer Science PUF - Hồ Chí Minh 2016/2017 Mutual exclusion Hardware solutions Semaphores IPC: Message passing
More informationSpin Locks and Contention
Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Modified for Software1 students by Lior Wolf and Mati Shomrat Kinds of Architectures
More informationBackground. The Critical-Section Problem Synchronisation Hardware Inefficient Spinning Semaphores Semaphore Examples Scheduling.
Background The Critical-Section Problem Background Race Conditions Solution Criteria to Critical-Section Problem Peterson s (Software) Solution Concurrent access to shared data may result in data inconsistency
More informationSpin Locks and Contention. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Spin Locks and Contention Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Real world concurrency Understanding hardware architecture What is contention How to
More informationSynchronization Principles
Synchronization Principles Gordon College Stephen Brinton The Problem with Concurrency Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms
More informationChapter 6: Process Synchronization. Module 6: Process Synchronization
Chapter 6: Process Synchronization Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization
More informationProcess Management And Synchronization
Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the
More informationChapter 6: Process Synchronization
Chapter 6: Process Synchronization Objectives Introduce Concept of Critical-Section Problem Hardware and Software Solutions of Critical-Section Problem Concept of Atomic Transaction Operating Systems CS
More informationModule 6: Process Synchronization. Operating System Concepts with Java 8 th Edition
Module 6: Process Synchronization 6.1 Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores
More informationCS370 Operating Systems
CS370 Operating Systems Colorado State University Yashwant K Malaiya Spring 1018 L11 Synchronization Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1 FAQ Multilevel feedback queue:
More informationChapter 5: Process Synchronization. Operating System Concepts 9 th Edition
Chapter 5: Process Synchronization Silberschatz, Galvin and Gagne 2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks
More informationProcess Synchronization
Chapter 7 Process Synchronization 1 Chapter s Content Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors 2 Background
More informationChapter 7: Process Synchronization. Background
Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris
More informationImplementing Mutual Exclusion. Sarah Diesburg Operating Systems CS 3430
Implementing Mutual Exclusion Sarah Diesburg Operating Systems CS 3430 From the Previous Lecture The too much milk example shows that writing concurrent programs directly with load and store instructions
More informationAnnouncements. Office hours. Reading. W office hour will be not starting next week. Chapter 7 (this whole week) CMSC 412 S02 (lect 7)
Office hours Announcements W office hour will be 10-11 not 11-12 starting next week Reading Chapter 7 (this whole week) 1 Problems with the Producer-Consumer Shared Memory Solution Consider the three address
More information1 The comparison of QC, SC and LIN
Com S 611 Spring Semester 2009 Algorithms for Multiprocessor Synchronization Lecture 5: Tuesday, 3rd February 2009 Instructor: Soma Chaudhuri Scribe: Jianrong Dong 1 The comparison of QC, SC and LIN Pi
More informationEECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution
1. (15 points) A system with two dual-core processors has four processors available for scheduling. A CPU-intensive application (e.g., a program that spends most of its time on computation, not I/O or
More informationModule 6: Process Synchronization
Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization Examples Atomic
More informationLesson 6: Process Synchronization
Lesson 6: Process Synchronization Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization
More informationProcess Synchronization
TDDI04 Concurrent Programming, Operating Systems, and Real-time Operating Systems Process Synchronization [SGG7] Chapter 6 Copyright Notice: The lecture notes are mainly based on Silberschatz s, Galvin
More informationProcess Synchronization
Process Synchronization Chapter 6 2015 Prof. Amr El-Kadi Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly
More informationChapter 6: Synchronization
Chapter 6: Synchronization Module 6: Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization
More informationAlgorithmic Verification. Algorithmic Verification. Model checking. Algorithmic verification. The software crisis (and hardware as well)
Algorithmic Verification The software crisis (and hardware as well) Algorithmic Verification Comp4151 Lecture 1-B Ansgar Fehnker Computer become more powerful (Moore s law) The quality of programs cannot
More informationChapter 6: Process Synchronization. Operating System Concepts 8 th Edition,
Chapter 6: Process Synchronization, Silberschatz, Galvin and Gagne 2009 Module 6: Process Synchronization Background The Critical-Section Problem Peterson s Solution Synchronization Hardware Semaphores
More informationIntroduction to Concurrency and Multicore Programming. Slides adapted from Art of Multicore Programming by Herlihy and Shavit
Introduction to Concurrency and Multicore Programming Slides adapted from Art of Multicore Programming by Herlihy and Shavit Overview Introduction Mutual Exclusion Linearizability Concurrent Data Structure
More informationSynchronization. Race Condition. The Critical-Section Problem Solution. The Synchronization Problem. Typical Process P i. Peterson s Solution
Race Condition Synchronization CSCI 315 Operating Systems Design Department of Computer Science A race occurs when the correctness of a program depends on one thread reaching point x in its control flow
More informationLecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)
Lecture Topics Today: Concurrency (Stallings, chapter 5.1-5.4, 5.7) Next: Exam #1 1 Announcements Self-Study Exercise #5 Project #3 (due 9/28) Project #4 (due 10/12) 2 Exam #1 Tuesday, 10/3 during lecture
More informationBackground. Old Producer Process Code. Improving the Bounded Buffer. Old Consumer Process Code
Old Producer Process Code Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Our
More informationDept. of CSE, York Univ. 1
EECS 3221.3 Operating System Fundamentals No.5 Process Synchronization(1) Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University Background: cooperating processes with shared
More informationCOMP Parallel Computing. CC-NUMA (2) Memory Consistency
COMP 633 - Parallel Computing Lecture 11 September 26, 2017 Memory Consistency Reading Patterson & Hennesey, Computer Architecture (2 nd Ed.) secn 8.6 a condensed treatment of consistency models Coherence
More informationPart II Process Management Chapter 6: Process Synchronization
Part II Process Management Chapter 6: Process Synchronization 1 Process Synchronization Why is synchronization needed? Race Conditions Critical Sections Pure Software Solutions Hardware Support Semaphores
More informationCS4411 Intro. to Operating Systems Exam 1 Fall points 9 pages
CS4411 Intro. to Operating Systems Exam 1 Fall 2009 1 CS4411 Intro. to Operating Systems Exam 1 Fall 2009 150 points 9 pages Name: Most of the following questions only require very short answers. Usually
More informationBackground. Module 6: Process Synchronization. Bounded-Buffer (Cont.) Bounded-Buffer. Background
Module 6: Process Synchronization Background Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization
More informationConcurrency Control. [R&G] Chapter 17 CS432 1
Concurrency Control [R&G] Chapter 17 CS432 1 Conflict Serializable Schedules Two schedules are conflict equivalent if: Involve the same actions of the same transactions Every pair of conflicting actions
More informationChapter 6 Synchronization
Chapter 6 Synchronization Da-Wei Chang CSIE.NCKU Source: Abraham Silberschatz, Peter B. Galvin, and Greg Gagne, "Operating System Concepts", 9th Edition, Wiley. 1 Outline Background The Critical-Section
More informationPESIT Bangalore South Campus
INTERNAL ASSESSMENT TEST II Date: 04/04/2018 Max Marks: 40 Subject & Code: Operating Systems 15CS64 Semester: VI (A & B) Name of the faculty: Mrs.Sharmila Banu.A Time: 8.30 am 10.00 am Answer any FIVE
More informationLinked Lists: Locking, Lock- Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Linked Lists: Locking, Lock- Free, and Beyond Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Coarse-Grained Synchronization Each method locks the object Avoid
More informationSynchronization. CS 475, Spring 2018 Concurrent & Distributed Systems
Synchronization CS 475, Spring 2018 Concurrent & Distributed Systems Review: Threads: Memory View code heap data files code heap data files stack stack stack stack m1 m1 a1 b1 m2 m2 a2 b2 m3 m3 a3 m4 m4
More informationSynchronization API of Pthread Mutex: lock, unlock, try_lock CondVar: wait, signal, signal_broadcast. Synchronization
CS341: Operating System Lect20 : 16 th Sept 2014 Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Synchronization API of Pthread Mutex: lock, unlock, try_lock CondVar: wait,
More informationUniversality of Consensus. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Universality of Consensus Companion slides for The by Maurice Herlihy & Nir Shavit Turing Computability 1 0 1 1 0 1 0 A mathematical model of computation Computable = Computable on a T-Machine 2 Shared-Memory
More informationConstant RMR Transformation to Augment Reader-Writer Locks with Atomic Upgrade/Downgrade Support
Constant RMR Transformation to Augment Reader-Writer Locks with Atomic Upgrade/Downgrade Support Jake Stern Leichtling Thesis Advisor: Prasad Jayanti With significant contributions from Michael Diamond.
More informationLinked Lists: Locking, Lock-Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Linked Lists: Locking, Lock-Free, and Beyond Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Concurrent Objects Adding threads should not lower throughput Contention
More informationDD2451 Parallel and Distributed Computing --- FDD3008 Distributed Algorithms
DD2451 Parallel and Distributed Computing --- FDD3008 Distributed Algorithms Lecture 3 Atomic Registers Mads Dam Autumn/Winter 2011 This Lecture Registers: Shared memory loca6ons that can be read and wri'en
More informationLecture 3: Synchronization & Deadlocks
Lecture 3: Synchronization & Deadlocks Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating
More informationLecture 5 Threads and Pthreads II
CSCI-GA.3033-017 Special Topics: Multicore Programming Lecture 5 Threads and Pthreads II Christopher Mitchell, Ph.D. cmitchell@cs.nyu.edu http://z80.me Context We re exploring the layers of an application
More informationConcurrency Control. Conflict Serializable Schedules. Example. Chapter 17
Concurrency Control Chapter 17 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Conflict Serializable Schedules Two schedules are conflict equivalent if: Involve the same actions of the
More informationSTUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total
University of Minnesota Department of Computer Science CSci 5103 - Fall 2016 (Instructor: Tripathi) Midterm Exam 1 Date: October 17, 2016 (4:00 5:15 pm) (Time: 75 minutes) Total Points 100 This exam contains
More informationOperating Systems CMPSC 473. Synchronization February 21, Lecture 11 Instructor: Trent Jaeger
Operating Systems CMPSC 473 Synchronization February 21, 2008 - Lecture 11 Instructor: Trent Jaeger Last class: CPU Scheduling Today: A little more scheduling Start synchronization Little s Law Evaluating
More informationIntroduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit. Art of Multiprocessor Programming
Introduction Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Art of Multiprocessor Programming Moore s Law Transistor count still rising Clock speed flattening
More informationDistributed Computing through Combinatorial Topology MITRO207, P4, 2017
Distributed Computing through MITRO207, P4, 2017 Administrivia Language: (fr)anglais? Lectures: Fridays (28.04, 20.05-23.06, 30.06), Thursday (29.06), 8:30-11:45, B555-557 Web page: http://perso.telecom-paristech.fr/~kuznetso/
More informationNondeterministic Programming
6.172 Performance Engineering of Software Systems LECTURE 15 Nondeterministic Programming Charles E. Leiserson November 2, 2010 2010 Charles E. Leiserson 1 Determinism Definition. A program is deterministic
More informationMidterm on next week Tuesday May 4. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9
CS 361 Concurrent programming Drexel University Fall 2004 Lecture 9 Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce
More informationConcurrency. On multiprocessors, several threads can execute simultaneously, one on each processor.
Synchronization 1 Concurrency On multiprocessors, several threads can execute simultaneously, one on each processor. On uniprocessors, only one thread executes at a time. However, because of preemption
More information