Slide 1

Slide 1 text

@Scalone Concurrency in the imperative and functional world

Slide 2

Slide 2 text

Thiago Scalone [email protected] @scalone

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

… nothing new … DISCLAIMER

Slide 7

Slide 7 text

If you don't understand concurrency… it isn’t problem if doesn't make part of your day. DISCLAIMER

Slide 8

Slide 8 text

POINT

Slide 9

Slide 9 text

Context 1

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

… and the light …

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Context 2

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Concurrency

Slide 21

Slide 21 text

Concurrency Parallelism

Slide 22

Slide 22 text

“Dealing a lot of things at once Rob Pike about Concurrency

Slide 23

Slide 23 text

“Doing a lot of things at once Rob Pike about Parallelism

Slide 24

Slide 24 text

@Scalone

Slide 25

Slide 25 text

@Scalone

Slide 26

Slide 26 text

@Scalone

Slide 27

Slide 27 text

@Scalone

Slide 28

Slide 28 text

@Scalone

Slide 29

Slide 29 text

@Scalone

Slide 30

Slide 30 text

@Scalone

Slide 31

Slide 31 text

@Scalone

Slide 32

Slide 32 text

Context 3

Slide 33

Slide 33 text

Imperative

Slide 34

Slide 34 text

Imperative

Slide 35

Slide 35 text

Imperative defines computation as statements that change a program state

Slide 36

Slide 36 text

Imperative

Slide 37

Slide 37 text

Imperative

Slide 38

Slide 38 text

Functional

Slide 39

Slide 39 text

Functional treats computation as the evaluation of mathematical functions and avoids state and mutable data

Slide 40

Slide 40 text

Functional treats computation as the evaluation of mathematical functions and avoids state and mutable data

Slide 41

Slide 41 text

Functional treats computation as the evaluation of mathematical functions and avoids state and mutable data

Slide 42

Slide 42 text

Functional

Slide 43

Slide 43 text

Functional

Slide 44

Slide 44 text

Functional

Slide 45

Slide 45 text

Functional

Slide 46

Slide 46 text

Functional

Slide 47

Slide 47 text

Functional

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

Concurrency

Slide 50

Slide 50 text

Threads

Slide 51

Slide 51 text

Thread and Locks

Slide 52

Slide 52 text

Thread and Locks

Slide 53

Slide 53 text

Thread and Locks

Slide 54

Slide 54 text

Thread and Locks

Slide 55

Slide 55 text

Thread and Locks

Slide 56

Slide 56 text

Thread and Locks

Slide 57

Slide 57 text

Thread and Locks

Slide 58

Slide 58 text

Thread and Locks

Slide 59

Slide 59 text

Java = Imperative

Slide 60

Slide 60 text

Thread and Locks I don't know the answer

Slide 61

Slide 61 text

Thread and Locks Mutable State

Slide 62

Slide 62 text

Thread and Locks Race condition

Slide 63

Slide 63 text

Race Condition the output is dependent on the sequence or timing of other uncontrollable events

Slide 64

Slide 64 text

Thread and Locks The meaning of life is: 0

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

Thread and Locks The meaning of life is: 0

Slide 67

Slide 67 text

Thread and Locks

Slide 68

Slide 68 text

Thread and Locks

Slide 69

Slide 69 text

Thread and Locks

Slide 70

Slide 70 text

Thread and Locks

Slide 71

Slide 71 text

Thread and Locks

Slide 72

Slide 72 text

Thread and Locks

Slide 73

Slide 73 text

Thread and Locks

Slide 74

Slide 74 text

Thread and Locks

Slide 75

Slide 75 text

Thread and Locks Optimization

Slide 76

Slide 76 text

Optimization the compiler is allowed to statically optimize your code by reordering things

Slide 77

Slide 77 text

Optimization the compiler is allowed to statically optimize your code by reordering things

Slide 78

Slide 78 text

Optimization the JVM is allowed to dynamically optimize your code by reordering things

Slide 79

Slide 79 text

Optimization the JVM is allowed to dynamically optimize your code by reordering things

Slide 80

Slide 80 text

Optimization the hardware you’re running on is allowed to optimize performance by reordering things

Slide 81

Slide 81 text

Optimization the hardware you’re running on is allowed to optimize performance by reordering things

Slide 82

Slide 82 text

Imperative

Slide 83

Slide 83 text

Imperative Thread Pool Mutual Exclusion Mutiple Locks - Deadlock Excessive Contention

Slide 84

Slide 84 text

Functional

Slide 85

Slide 85 text

Functional treats computation as the evaluation of mathematical functions and avoids state and mutable data

Slide 86

Slide 86 text

Functional treats computation as the evaluation of mathematical functions and avoids state and mutable data

Slide 87

Slide 87 text

Functional treats computation as the evaluation of mathematical functions and avoids state and mutable data

Slide 88

Slide 88 text

Functional - Bound/Unbound Variable

Slide 89

Slide 89 text

Functional - Bound/Unbound Variable

Slide 90

Slide 90 text

Functional - Bound/Unbound Variable

Slide 91

Slide 91 text

Functional - Bound/Unbound Variable

Slide 92

Slide 92 text

Functional - Bound/Unbound Variable

Slide 93

Slide 93 text

Determinism

Slide 94

Slide 94 text

Determinism - Same In => Same out f(x)

Slide 95

Slide 95 text

Determinism - Same In => Same out no disk I/O f(x)

Slide 96

Slide 96 text

Determinism - Same In => Same out no disk I/O no random() f(x)

Slide 97

Slide 97 text

Determinism - Same In => Same out no disk I/O no side effects no random() always the same result f(x)

Slide 98

Slide 98 text

Determinism - Same In => Same out no disk I/O no side effects no random() f(x)

Slide 99

Slide 99 text

Determinism

Slide 100

Slide 100 text

Determinism

Slide 101

Slide 101 text

Determinism 42

Slide 102

Slide 102 text

Determinism

Slide 103

Slide 103 text

Determinism + Concurrency

Slide 104

Slide 104 text

Determinism + Concurrency

Slide 105

Slide 105 text

Determinism + Concurrency

Slide 106

Slide 106 text

Determinism + Concurrency

Slide 107

Slide 107 text

Determinism + Concurrency

Slide 108

Slide 108 text

Concurrency Models

Slide 109

Slide 109 text

Actor

Slide 110

Slide 110 text

Actor

Slide 111

Slide 111 text

Actor An object which encapsulates state and communicates with other actors by exchaging messages

Slide 112

Slide 112 text

Actor accumulator

Slide 113

Slide 113 text

Actor accumulator

Slide 114

Slide 114 text

Goroutines and Channels

Slide 115

Slide 115 text

Goroutines and Channels

Slide 116

Slide 116 text

Microthreads with a internal scheduler Goroutines and Channels

Slide 117

Slide 117 text

Goroutines and Channels

Slide 118

Slide 118 text

Goroutines and Channels

Slide 119

Slide 119 text

Goroutines and Channels

Slide 120

Slide 120 text

Goroutines and Channels

Slide 121

Slide 121 text

Goroutines and Channels

Slide 122

Slide 122 text

Goroutines and Channels

Slide 123

Slide 123 text

Goroutines and Channels

Slide 124

Slide 124 text

Goroutines and Channels

Slide 125

Slide 125 text

References

Slide 126

Slide 126 text

References

Slide 127

Slide 127 text

References

Slide 128

Slide 128 text

THANK YOU! @Scalone