Grace Safe Multithreaded Programming for CC Emery Berger
Grace: Safe Multithreaded Programming for C/C++ Emery Berger University of Massachusetts, UPC/BSC www. cs. umass. edu/~emery NIVERSITY OF OF M ASSACHUSETTS, , A U MHERST • • Department UNIVERSITY MASSACHUSETTS AMHERST Department of 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
“ 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
race conditions Grace atomicity violations deadlock order violations
race conditions Grace atomicity violations deadlock order violations
race conditions Grace atomicity violations deadlock order violations sequential
Grace % g++ myprog. cpp –lpthread –o myprog
Grace % g++ myprog. cpp –lgrace –o myprog
Grace % g++ myprog. cpp –lgrace sequential –o myprog
Grace % g++ myprog. cpp –lgrace sequential race conditions atomicity violations deadlock order violations –o myprog
Grace % g++ myprog. cpp –lgrace sequential race conditions atomicity violations deadlock order violations –o myprog
Safe and (usually) fast…
benign race
Grace 1. sequential + ?
Grace 1. 2. sequential + ?
Grace 1. 2. 3. sequential + ?
1. sequential + ?
1. sequential t 1 = spawn f(x); t 2 = spawn g(y); sync; + ?
1. sequential + ? spawn f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync;
1. sequential + ? spawn f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync; f(x)
1. sequential + ? spawn f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync; f(x) spawn g(y)
1. sequential + ? spawn f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync; f(x) spawn g(y)
1. sequential + ? spawn f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync; f(x) spawn g(y) sync g(y)
1. sequential + ? spawn f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync; f(x) spawn g(y) sync g(y)
1. sequential + ? spawn f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync; f(x) spawn g(y) left-to-right, depth-first ordering sync
1. sequential + ? f(x) t 1 = spawn f(x); t 2 = spawn g(y); sync; g(y)
1. sequential t 1 = spawn f(x); t 2 = spawn g(y); sync; + ? “ f(x) g(y) ”
1. “ sequential f(x) g(y) ” + ?
1. “ f(x) g(y) sequential + ? ” race conditions atomicity violations deadlock order violations
1. “ f(x) g(y) sequential + ? ” race conditions atomicity violations deadlock order violations
1. “ f(x) g(y) sequential + ? ” race conditions atomicity violations deadlock order violations
1. “ f(x) g(y) sequential + ? ” race conditions atomicity violations deadlock order violations
1. “ f(x) g(y) sequential + ? ” race conditions atomicity violations deadlock order violations
1. “ f(x) g(y) sequential + ? ” race conditions atomicity violations deadlock order violations
1. “ f(x) g(y) sequential + ? ” race conditions atomicity violations deadlock order violations
1. “ sequential f(x) g(y) ” + ?
1. “ sequential f(x) g(y) ” + ?
1. “ sequential f(x) g(y) ” + ?
1. “ sequential f(x) g(y) ” + ?
1. “ sequential f(x) g(y) ” + ?
1. “ sequential f(x) g(y) + ? ” Fork-join (e. g. , map-reduce, Cilk, TBB…)
2. ? What’s under the hood?
2. ? “Magic!”
2. ? t 1 = spawn f(x); t 2 = spawn g(y); sync;
2. ? t 1 = spawn f(x); t 2 = spawn g(y); sync; if (!fork()) f(x); if (!fork()) g(y); // check;
2. spawn f(x) ? f(x) spawn g(y) sync if (!fork()) f(x); if (!fork()) g(y); // check; g(y)
2. spawn f(x) ? f(x) spawn g(y) sync if (!fork()) f(x); if (!fork()) g(y); // check; g(y)
2. spawn f(x) ? f(x) spawn g(y) sync Note: Nested threads ok if (!fork()) f(x); if (!fork()) g(y); // check; g(y)
2. spawn f(x) ? f(x) mmap spawn g(y) sync g(y)
2. spawn f(x) ? f(x) mmap spawn g(y) sync g(y)
2. spawn f(x) ? f(x) mmap spawn g(y) sync g(y)
2. spawn f(x) ? f(x) spawn g(y) sync g(y)
2. spawn f(x) ? f(x) 1 spawn g(y) sync g(y)
2. spawn f(x) ? f(x) 1 spawn g(y) sync 2
2. ? scalable heap + aligned globals I/O (buffering + ordering)
3. More detailed results…
Grace sequential race conditions atomicity violations deadlock order violations
Grace sequential race conditions atomicity violations deadlock order violations
Grace sequential race conditions atomicity violations deadlock order violations
Grace sequential race conditions atomicity violations deadlock order violations % g++ myprog. cpp –lgrace –o myprog
“Moltes gràcies”
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. ? + + UNIVERSITY OF MASSACHUSETTS , AMHERST • Department of Computer Science
- Slides: 118