Mutual Exclusion. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
|
|
- Arleen Foster
- 5 years ago
- Views:
Transcription
1 Mutual Exclusion Companion slides for The by Maurice Herlihy & Nir Shavit
2 Mutual Exclusion In his 1965 paper E. W. Dijkstra wrote: "Given in this paper is a solution to a problem which, to the knowledge of the author, has been an open question since at least 1962, irrespective of the solvability. [...] Although the setting of the problem might seem somewhat academic at first, the author trusts that anyone familiar with the logical problems that arise in computer coupling will appreciate the significance of the fact that this problem indeed can be solved." 2
3 Absolute, true and mathematical time, of itself and from its own nature, flows equably without relation to anything external. (I. Newton, 1689) Time is, like, Nature s way of making sure that everything doesn t happen all at once. (Anonymous, circa 1968) time Time 3
4 Events An event a 0 of thread A is Instantaneous No simultaneous events (break ties) a 0 time 4
5 A thread A is (formally) a sequence a 0, a 1,... of events Trace model Threads Notation: a 0 è a 1 indicates order a 0 a 1 a 2 time 5
6 Example Thread Events Assign to shared variable Assign to local variable Invoke method Return from method Lots of other things mas nem todos são de fato instantâneos 6
7 Threads are State Machines a 0 Events are transitions a 3 a 2 a 1 estado: variáveis globais pilha: variáveis locais, chamadas... 7
8 States Thread State Program counter Local variables System state Object fields (shared variables) Union of thread states 8
9 Concurrency Thread A time 9
10 Concurrency Thread A time Thread B time 10
11 Interleavings Events of two or more threads Interleaved Not necessarily independent (why?) time 11
12 Intervals An interval A 0 =(a 0,a 1 ) is Time between events a 0 and a 1 a 0 a 1 A 0 time 12
13 Intervals may Overlap b 0 B 0 b 1 a 0 A 0 a 1 time 13
14 Intervals may be Disjoint b 0 B 0 b 1 a 0 A 0 a 1 time 14
15 Precedence Interval A 0 precedes interval B 0 a 0 A 0 a 1 b 0 B 0 b 1 time 15
16 Precedence Notation: A 0 è B 0 Formally, End event of A 0 before start event of B 0 Also called happens before or precedes 16
17 Precedence Ordering Remark: A 0 è B 0 is just like saying 1066 AD è 1492 AD, Middle Ages è Renaissance, Oh wait, what about this week vs this month? 17
18 Precedence Ordering Never true that A è A If A è B then not true that B è A If A è B & B è C then A è C Funny thing: A è B & B è A might both be false! 18
19 Irreflexive: Partial Orders (you may know this already) Never true that A è A Antisymmetric: If A Transitive: è B then not true that B è A If A è B & B è C then A è C 19
20 Total Orders (you may know this already) Also Irreflexive Antisymmetric Transitive Except that for every distinct A, B, Either A è B or B è A 20
21 Locks (Mutual Exclusion) public interface Lock { public void lock(); public void unlock(); 21
22 Using Locks public class Counter { private long value; private Lock lock; public long getandincrement() { lock.lock(); try { int temp = value; value = value + 1; finally { lock.unlock(); return temp; 22
23 Using Locks public class Counter { private long value; private Lock lock; public long getandincrement() { lock.lock(); try { int temp = value; value = value + 1; finally { lock.unlock(); return temp; acquire Lock 23
24 Using Locks public class Counter { private long value; private Lock lock; public long getandincrement() { lock.lock(); try { int temp = value; value = value + 1; finally { lock.unlock(); return temp; Release lock (no matter what) 24
25 Using Locks public class Counter { private long value; private Lock lock; public long getandincrement() { lock.lock(); try { int temp = value; value = value + 1; finally { lock.unlock(); return temp; Critical section 25
26 Two-Thread vs n -Thread Solutions Two-thread solutions first Illustrate most basic ideas Fits on one slide Then n-thread solutions 26
27 Two-Thread Conventions class implements Lock { // thread-local index, 0 or 1 public void lock() { int i = ThreadID.get(); int j = 1 - i; 27
28 Two-Thread Conventions class implements Lock { // thread-local index, 0 or 1 public void lock() { int i = ThreadID.get(); int j = 1 - i; Henceforth: i is current thread, j is other thread 28
29 LockOne class LockOne implements Lock { private boolean[] flag = new boolean[2]; public void lock() { flag[i] = true; while (flag[j]) { 29
30 LockOne class LockOne implements Lock { private boolean[] flag = new boolean[2]; public void lock() { flag[i] = true; while (flag[j]) { Set my flag 30
31 LockOne class LockOne implements Lock { private boolean[] flag = new boolean[2]; public void lock() { flag[i] = true; while (flag[j]) { Set my flag Wait for other flag to go false 31
32 LockOne Satisfies Mutual Exclusion Assume CS j overlaps A CS k B Consider each thread's last (j-th and k-th) read and write in the lock() method before entering Derive a contradiction 32
33 From the Code write A (flag[a]=true) à read A (flag[b]==false) à CS A write B (flag[b]=true) à read B (flag[a]==false) à CS B class LockOne implements Lock { public void lock() { flag[i] = true; while (flag[j]) { 33
34 From the Assumption read A (flag[b]==false) à write B (flag[b]=true) read B (flag[a]==false) à write A (flag[b]=true) 34
35 Combining Assumptions: read A (flag[b]==false) à write B (flag[b]=true) read B (flag[a]==false) à write A (flag[a]=true) From the code write A (flag[a]=true) à read A (flag[b]==false) write B (flag[b]=true) à read B (flag[a]==false) 35
36 Combining Assumptions: read A (flag[b]==false) à write B (flag[b]=true) read B (flag[a]==false) à write A (flag[a]=true) From the code write A (flag[a]=true) à read A (flag[b]==false) write B (flag[b]=true) à read B (flag[a]==false) 36
37 Combining Assumptions: read A (flag[b]==false) à write B (flag[b]=true) read B (flag[a]==false) à write A (flag[a]=true) From the code write A (flag[a]=true) à read A (flag[b]==false) write B (flag[b]=true) à read B (flag[a]==false) 37
38 Combining Assumptions: read A (flag[b]==false) à write B (flag[b]=true) read B (flag[a]==false) à write A (flag[a]=true) From the code write A (flag[a]=true) à read A (flag[b]==false) write B (flag[b]=true) à read B (flag[a]==false) 38
39 Combining Assumptions: read A (flag[b]==false) à write B (flag[b]=true) read B (flag[a]==false) à write A (flag[a]=true) From the code write A (flag[a]=true) à read A (flag[b]==false) write B (flag[b]=true) à read B (flag[a]==false) 39
40 Combining Assumptions: read A (flag[b]==false) à write B (flag[b]=true) read B (flag[a]==false) à write A (flag[a]=true) From the code write A (flag[a]=true) à read A (flag[b]==false) write B (flag[b]=true) à read B (flag[a]==false) 40
41 Cycle! 41
42 Deadlock Freedom LockOne Fails deadlock-freedom Concurrent execution can deadlock flag[i] = true; flag[j] = true; while (flag[j]){ while (flag[i]){ Sequential executions OK 42
43 LockTwo public class LockTwo implements Lock { private int victim; public void lock() { victim = i; while (victim == i) {; public void unlock() { 43
44 LockTwo public class LockTwo implements Lock { private int victim; public void lock() { victim = i; while (victim == i) {; public void unlock() { Let other go first 44
45 LockTwo public class LockTwo implements Lock { private int victim; public void lock() { victim = i; while (victim == i) {; public void unlock() { Wait for permission 45
46 LockTwo public class Lock2 implements Lock { private int victim; public void lock() { victim = i; while (victim == i) {; public void unlock() { Nothing to do 46
47 LockTwo Claims Satisfies mutual exclusion If thread i in CS Then victim == j Cannot be both 0 and 1 Not deadlock free Sequential execution deadlocks Concurrent execution does not public void LockTwo() { victim = i; while (victim == i) {; 47
48 Peterson s Algorithm public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {; public void unlock() { flag[i] = false; 48
49 Peterson s Algorithm Announce I m interested public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {; public void unlock() { flag[i] = false; 49
50 Peterson s Algorithm Announce I m interested public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {; public void unlock() { flag[i] = false; Defer to other 50
51 Peterson s Algorithm public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {; public void unlock() { flag[i] = false; Announce I m interested Defer to other Wait while other interested & I m the victim 51
52 Peterson s Algorithm public void lock() { flag[i] = true; victim = i; while (flag[j] && victim == i) {; public void unlock() { flag[i] = false; No longer interested Announce I m interested Defer to other Wait while other interested & I m the victim 52
53 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 53
54 do código: write A (flag[a]=true) à write A (victim=a) à read A (flag[b]) à read A (victim) à CS A write B (flag[b]=true) à write B (victim=b) à read B (flag[a]) à read B (victim) à CS B vamos assumir: write B (victim=b) à write A (victim=a) como A entrou na RC: write A (victim=a) à read A (flag[b] == false) mas então write B (flag[b]=true) à write B (victim=b) à write A (victim=a) à read A (flag[b] == false) 54
55 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 55
56 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; 56
57 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 57
58 Filter class Filter implements Lock { int[] level; // level[i] for thread i int[] victim; // victim[l] for level L public Filter(int n) { level = new int[n]; victim = new int[n]; for (int i = 1; i < n; i++) { level[i] = 0; level Thread 2 at level victim n-1 58 n-1
59 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; 59
60 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 60
61 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 61
62 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 62
63 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; 63
64 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; the loop Thread enters level L when it completes 64
65 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 65
66 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 66
67 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 in level[l] and since victim[l] == A could not have entered 67
68 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) {; 68
69 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) {; 69
70 By Assumption (3) write B (victim[l]=b)è write A (victim[l]=a) By assumption, A is the last thread to write victim[l] 70
71 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]) 71
72 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]) 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) {; 72
73 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! 73
74 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 74
75 Bounded Waiting Want stronger fairness guarantees Thread not overtaken too much Need to adjust definitions. 75
76 Bounded Waiting Divide lock() method into 2 parts: Doorway interval: Written D A always finishes in finite steps Waiting interval: Written W A may take unbounded steps 76
77 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. 77
78 Fairness Again Filter Lock satisfies properties: No one starves But very weak fairness Not r-bounded for any r! That s pretty lame 78
79 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 79
80 Bakery Algorithm class Bakery implements Lock { boolean[] flag; 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; 80
81 Bakery Algorithm class Bakery implements Lock { boolean[] flag; 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; 0 2 f f t f f t f f CS 6 n-1 81
82 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)); 82
83 Bakery Algorithm class Bakery implements Lock { Doorway 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)); 83
84 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)); 84
85 Bakery Algorithm Take increasing label (read labels in some arbitrary order) 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)); 85
86 Bakery Algorithm Someone is interested 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)); 86
87 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 87
88 Bakery Algorithm class Bakery implements Lock { public void unlock() { flag[i] = false; 88
89 Bakery Algorithm class Bakery implements Lock { No longer interested public void unlock() { flag[i] = false; labels are always increasing 89
90 No Deadlock There is always one thread with earliest label Ties are impossible (why?) 90
91 First-Come-First-Served If D A è D B then A s label is smaller And: 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)); 91
92 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)); 92
93 Mutual Exclusion Labels are strictly increasing so B must have seen flag[a] == false 93
94 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 94
95 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 95
96 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)); 96
97 Bakery Y2 32 K Bug Mutex breaks if label[i] overflows 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)); 97
98 Does Overflow Actually Matter? Yes Y2K 18 January 2038 (Unix time_t rollover) 16-bit counters No 64-bit counters Maybe 32-bit counters 98
99 palavras de cautela esses algoritmos assumem coisas que achamos intuitivas instruções em uma thread serão executadas na ordem em que as enxergamos... mas compilador pode pensar diferente... 99
Mutual 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 informationProgramming 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 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 informationPeterson s Algorithm
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 Mutual
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationConcurrent Objects. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Concurrent Objects Companion slides for The by Maurice Herlihy & Nir Shavit Concurrent Computation memory object object 2 Objectivism What is a concurrent object? How do we describe one? How do we implement
More informationCoSc 450: Programming Paradigms. The Critical Section Problem
CoSc 450: Programming Paradigms 03 The Critical Section Problem Algorithm 3.1: Critical section problem global variables p q local variables local variables loop forever loop forever non-critical section
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 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 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 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 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 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 informationTopology and Topological Spaces
Topology and Topological Spaces Mathematical spaces such as vector spaces, normed vector spaces (Banach spaces), and metric spaces are generalizations of ideas that are familiar in R or in R n. For example,
More informationSynchronization: Semaphores
Illinois Institute of Technology Lecture 26 4/25 solved Synchronization: Semaphores CS 536: Science of Programming, Spring 2018 A. Why Avoiding interference, while good, isn t the same as coordinating
More informationConcurrency: Mutual Exclusion and Synchronization. Concurrency
Concurrency: Mutual Exclusion and Synchronization Chapter 5 1 Concurrency Multiple applications Structured applications Operating system structure 2 1 Concurrency 3 Difficulties of Concurrency Sharing
More informationThread Synchronization: Too Much Milk
Thread Synchronization: Too Much Milk 1 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing mutual exclusion with memory reads and writes
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 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 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 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 informationSafety and liveness for critical sections
Safety and liveness for critical sections! At most k threads are concurrently in the critical section A. Safety B. Liveness C. Both! A thread that wants to enter the critical section will eventually succeed
More informationConcurrent Objects and Linearizability
Chapter 3 Concurrent Objects and Linearizability 3.1 Specifying Objects An object in languages such as Java and C++ is a container for data. Each object provides a set of methods that are the only way
More informationCSCI 447 Operating Systems Filip Jagodzinski
Filip Jagodzinski Announcements Reading Task Should take 30 minutes-ish maximum Homework 2 Book questions including two custom ones will be posted to the course website today Programming tasks will be
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 informationChapter 7: Process Synchronization!
Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Monitors 7.1 Background Concurrent access to shared
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 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 informationConcurrency, Mutual Exclusion and Synchronization C H A P T E R 5
Concurrency, Mutual Exclusion and Synchronization C H A P T E R 5 Multiple Processes OS design is concerned with the management of processes and threads: Multiprogramming Multiprocessing Distributed processing
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 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 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 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 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 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 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 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 informationMutual Exclusion and Synchronization
Mutual Exclusion and Synchronization Concurrency Defined Single processor multiprogramming system Interleaving of processes Multiprocessor systems Processes run in parallel on different processors Interleaving
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 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 informationProcess Synchronization (Part I)
Process Synchronization (Part I) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) Process Synchronization 1393/7/14 1 / 44 Motivation
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 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 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 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 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 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 informationProcess/Thread Synchronization
CSE325 Principles of Operating Systems Process/Thread Synchronization David Duggan dduggan@sandia.gov February 14, 2013 Reading Assignment 7 Chapter 7 Deadlocks, due 2/21 2/14/13 CSE325: Synchronization
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 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 informationDr. D. M. Akbar Hussain DE5 Department of Electronic Systems
Concurrency 1 Concurrency Execution of multiple processes. Multi-programming: Management of multiple processes within a uni- processor system, every system has this support, whether big, small or complex.
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 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: 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 informationProcess Synchronisation (contd.) Deadlock. Operating Systems. Spring CS5212
Operating Systems Spring 2009-2010 Outline Process Synchronisation (contd.) 1 Process Synchronisation (contd.) 2 Announcements Presentations: will be held on last teaching week during lectures make a 20-minute
More informationIntroduction to OS Synchronization MOS 2.3
Introduction to OS Synchronization MOS 2.3 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Challenge How can we help processes synchronize with each other? E.g., how
More informationPage 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "
Goals for Today" CS162 Operating Systems and Systems Programming Lecture 5 Semaphores, Conditional Variables" Atomic instruction sequence Continue with Synchronization Abstractions Semaphores, Monitors
More informationSynchronization Principles I
CSC 256/456: Operating Systems Synchronization Principles I John Criswell University of Rochester 1 Synchronization Principles Background Concurrent access to shared data may result in data inconsistency.
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 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 informationEXTENDING THE PRIORITY CEILING PROTOCOL USING READ/WRITE AFFECTED SETS MICHAEL A. SQUADRITO A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF THE
EXTENDING THE PRIORITY CEILING PROTOCOL USING READ/WRITE AFFECTED SETS BY MICHAEL A. SQUADRITO A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF MASTER OF SCIENCE IN COMPUTER
More informationIntroduction. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit
Introduction Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit Moore s Law Transistor count still rising Clock speed flattening sharply Art of Multiprocessor Programming
More informationReview of last lecture. Peer Quiz. DPHPC Overview. Goals of this lecture. Lock-based queue
Review of last lecture Design of Parallel and High-Performance Computing Fall 2016 Lecture: Linearizability Motivational video: https://www.youtube.com/watch?v=qx2driqxnbs Instructor: Torsten Hoefler &
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 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 informationFall 2004 CS414 Prelim 1
Fall 2004 CS414 Prelim 1 1. The Sim City Smoking Ban problem: In the Sim-City community Woobish most people smoke, but the laws of Sim City require that non-smokers be protected from passive smoke. So
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 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 informationReview of last lecture. Goals of this lecture. DPHPC Overview. Lock-based queue. Lock-based queue
Review of last lecture Design of Parallel and High-Performance Computing Fall 2013 Lecture: Linearizability Instructor: Torsten Hoefler & Markus Püschel TA: Timo Schneider Cache-coherence is not enough!
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 informationSynchronisation algorithms
Synchronisation algorithms - Lecture Notes - Elad Aigner-Horev July 2, 2017 Contents 1. Introduction 3 1.1. Synchronisation algorithms: definition............. 4 1.2. The OS scheduler: the enemy..................
More informationCSCI 447 Operating Systems Filip Jagodzinski
Filip Jagodzinski Announcements Homework 2 you have 2 weeks start now Book questions including two custom ones A single programming task File names and directories, class conventions homework2-script,
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 information