u niversity of m assachusetts, a mherst department of computer science grace: safe multithreaded...
TRANSCRIPT
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer ScienceUNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science
Grace: Safe Multithreaded Programming for C/C++
Emery BergerUniversity of Massachusetts, UPC/BSC
www.cs.umass.edu/~emery
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
“ ”
race condition
atomicity violation
deadlock
order violation
sequential
sequential
race conditions
race conditions
atomicity violations
race conditions
atomicity violations
deadlock
race conditions
atomicity violations
deadlock
order violations
Grace
race conditions
atomicity violations
deadlock
order violations
race conditions
atomicity violations
deadlock
order violations
Grace
race conditions
atomicity violations
deadlock
order violations
sequential
Grace
Grace
% g++ myprog.cpp –lpthread –o myprog
Grace
% g++ myprog.cpp –lgrace –o myprog
Grace
% g++ myprog.cpp –lgrace –o myprog
sequential
Grace
% g++ myprog.cpp –lgrace –o myprog
sequentialrace conditions
atomicity violations
deadlock
order violations
Grace
% g++ myprog.cpp –lgrace –o myprog
sequentialrace conditions
atomicity violations
deadlock
order violations
Safe and (usually) fast…
benign race
Grace
sequential + ?1.
Grace
sequential + ?1.
2.
Grace
sequential + ?1.
2.
3.
sequential + ?1.
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
spawnf(x)
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)
spawnf(x)
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)
spawnf(x)
spawng(y)
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)g(y)
spawnf(x)
spawng(y)
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)g(y)
spawnf(x)
spawng(y)
sync
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)g(y)
spawnf(x)
spawng(y)
sync
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)g(y)
spawnf(x)
spawng(y)
sync
left-to-right, depth-first ordering
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)
g(y)
sequential + ?1.
t1 = spawn f(x);t2 = spawn g(y);sync;
f(x)
g(y)
“ ”
sequential + ?1.
f(x)
g(y)
“ ”
sequential + ?1.
f(x)
g(y)
“ ”race conditions
atomicity violations
deadlock
order violations
sequential + ?1.
f(x)
g(y)
“ ”race conditions
atomicity violations
deadlock
order violations
sequential + ?1.
f(x)
g(y)
“ ”race conditions
atomicity violations
deadlock
order violations
sequential + ?1.
f(x)
g(y)
“ ”race conditions
atomicity violations
deadlock
order violations
sequential + ?1.
f(x)
g(y)
“ ”race conditions
atomicity violations
deadlock
order violations
sequential + ?1.
f(x)
g(y)
“ ”race conditions
atomicity violations
deadlock
order violations
sequential + ?1.
f(x)
g(y)
“ ”race conditions
atomicity violations
deadlock
order violations
sequential + ?1.
f(x)
g(y)
“ ”
sequential + ?1.
f(x)
g(y)
“ ”
sequential + ?1.
f(x)
g(y)
“ ”
sequential + ?1.
f(x)
g(y)
“ ”
sequential + ?1.
f(x)
g(y)
“ ”
sequential + ?1.
f(x)
g(y)
“ ”
Fork-join(e.g., map-reduce, Cilk, TBB…)
?2.
What’s under the hood?
?2.
“Magic!”
?2.
+
?2.
?2.
t1 = spawn f(x);t2 = spawn g(y);sync;
?2.
t1 = spawn f(x);t2 = spawn g(y);sync;
if (!fork()) f(x);if (!fork()) g(y);// check;
?2.
if (!fork()) f(x);if (!fork()) g(y);// check;
f(x)g(y)
spawnf(x)
spawng(y)
sync
?2.
if (!fork()) f(x);if (!fork()) g(y);// check;
f(x)g(y)
spawnf(x)
spawng(y)
sync
?2.
if (!fork()) f(x);if (!fork()) g(y);// check;
f(x)g(y)
spawnf(x)
spawng(y)
sync
Note:Nested threads ok
?2.f(x)
g(y)
spawnf(x)
spawng(y)
syncmmap
?2.f(x)
g(y)
spawnf(x)
spawng(y)
syncmmap
?2.f(x)
g(y)
spawnf(x)
spawng(y)
syncmmap
?2.f(x)
g(y)
spawnf(x)
spawng(y)
sync
?2.f(x)
g(y)
spawnf(x)
spawng(y)
sync
1
?2.f(x)
g(y)
spawnf(x)
spawng(y)
sync
12
?2.
scalable heap+ aligned globals
I/O (buffering + ordering)
3.
More detailed results…
Grace
sequentialrace conditions
atomicity violations
deadlock
order violations
Grace
sequentialrace conditions
atomicity violations
deadlock
order violations
Grace
sequentialrace conditions
atomicity violations
deadlock
order violations
Grace
sequentialrace conditions
atomicity violations
deadlock
order violations
% g++ myprog.cpp –lgrace –o myprog
“Moltes gràcies”
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
?2.
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
?2.
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
?2.
+
UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
?2.
+ +