Download presentation
Presentation is loading. Please wait.
Published byEmiliano Attebury Modified over 9 years ago
1
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Grace: Safe Multithreaded Programming for C/C++ Emery Berger University of Massachusetts, UPC/BSC www.cs.umass.edu/~emery
2
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science
24
“”
30
race condition
35
atomicity violation
38
deadlock
42
order violation
44
sequential
47
race conditions
48
atomicity violations
49
race conditions atomicity violations deadlock
50
race conditions atomicity violations deadlock order violations
52
Grace race conditions atomicity violations deadlock order violations
53
race conditions atomicity violations deadlock order violations Grace
54
race conditions atomicity violations deadlock order violations sequential Grace
55
% g++ myprog.cpp –lpthread –o myprog
56
Grace % g++ myprog.cpp –lgrace –o myprog
57
Grace % g++ myprog.cpp –lgrace –o myprog sequential
58
Grace % g++ myprog.cpp –lgrace –o myprog sequential race conditions atomicity violations deadlock order violations
59
Grace % g++ myprog.cpp –lgrace –o myprog sequential race conditions atomicity violations deadlock order violations
60
Safe and (usually) fast…
61
benign race
62
Grace sequential +?1.
63
Grace sequential +?1. 2.
64
Grace sequential +?1. 2. 3.
65
sequential +?1.
66
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync;
67
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; spawn f(x)
68
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) spawn f(x)
69
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) spawn f(x) spawn g(y)
70
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) g(y) spawn f(x) spawn g(y)
71
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) g(y) spawn f(x) spawn g(y) sync
72
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) g(y) spawn f(x) spawn g(y) sync
73
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) g(y) spawn f(x) spawn g(y) sync left-to-right, depth-first ordering
74
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) g(y)
75
sequential +?1. t1 = spawn f(x); t2 = spawn g(y); sync; f(x) g(y) “”
76
sequential +?1. f(x) g(y) “”
77
sequential +?1. f(x) g(y) “” race conditions atomicity violations deadlock order violations
78
sequential +?1. f(x) g(y) “” race conditions atomicity violations deadlock order violations
79
sequential +?1. f(x) g(y) “” race conditions atomicity violations deadlock order violations
80
sequential +?1. f(x) g(y) “” race conditions atomicity violations deadlock order violations
81
sequential +?1. f(x) g(y) “” race conditions atomicity violations deadlock order violations
82
sequential +?1. f(x) g(y) “” race conditions atomicity violations deadlock order violations
83
sequential +?1. f(x) g(y) “” race conditions atomicity violations deadlock order violations
84
sequential +?1. f(x) g(y) “”
85
sequential +?1. f(x) g(y) “”
86
sequential +?1. f(x) g(y) “”
87
sequential +?1. f(x) g(y) “”
88
sequential +?1. f(x) g(y) “”
89
sequential +?1. f(x) g(y) “” Fork-join (e.g., map-reduce, Cilk, TBB…)
90
? 2. What’s under the hood?
91
? 2. “Magic!”
92
? 2. +
93
?
94
? t1 = spawn f(x); t2 = spawn g(y); sync;
95
? 2. t1 = spawn f(x); t2 = spawn g(y); sync; if (!fork()) f(x); if (!fork()) g(y); // check;
96
? 2. if (!fork()) f(x); if (!fork()) g(y); // check; f(x) g(y) spawn f(x) spawn g(y) sync
97
? 2. if (!fork()) f(x); if (!fork()) g(y); // check; f(x) g(y) spawn f(x) spawn g(y) sync
98
? 2. if (!fork()) f(x); if (!fork()) g(y); // check; f(x) g(y) spawn f(x) spawn g(y) sync Note: Nested threads ok
99
? 2. f(x) g(y) spawn f(x) spawn g(y) sync mmap
100
? 2. f(x) g(y) spawn f(x) spawn g(y) sync mmap
101
? 2. f(x) g(y) spawn f(x) spawn g(y) sync mmap
102
? 2. f(x) g(y) spawn f(x) spawn g(y) sync
103
? 2. f(x) g(y) spawn f(x) spawn g(y) sync 1
104
? 2. f(x) g(y) spawn f(x) spawn g(y) sync 1 2
105
? 2. scalable heap + aligned globals I/O (buffering + ordering)
106
3. More detailed results…
110
Grace sequential race conditions atomicity violations deadlock order violations
111
Grace sequential race conditions atomicity violations deadlock order violations
112
Grace sequential race conditions atomicity violations deadlock order violations
113
Grace sequential race conditions atomicity violations deadlock order violations % g++ myprog.cpp –lgrace –o myprog
114
“Moltes gràcies”
115
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science ? 2.
116
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science ? 2.
117
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science ? 2. +
118
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science ? 2. ++
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.