Download presentation

Presentation is loading. Please wait.

Published byEmiliano Attebury Modified about 1 year 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

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24
“”

25

26

27

28

29

30
race condition

31

32

33

34

35
atomicity violation

36

37

38
deadlock

39

40

41

42
order violation

43

44
sequential

45

46

47
race conditions

48
atomicity violations

49
race conditions atomicity violations deadlock

50
race conditions atomicity violations deadlock order violations

51

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…

107

108

109

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

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google