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

Context 1

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Context 2

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Concurrency

Slide 17

Slide 17 text

Concurrency Parallelism

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

@Scalone

Slide 21

Slide 21 text

@Scalone

Slide 22

Slide 22 text

@Scalone

Slide 23

Slide 23 text

@Scalone

Slide 24

Slide 24 text

@Scalone

Slide 25

Slide 25 text

@Scalone

Slide 26

Slide 26 text

@Scalone

Slide 27

Slide 27 text

Context 3

Slide 28

Slide 28 text

Imperative

Slide 29

Slide 29 text

Imperative

Slide 30

Slide 30 text

Imperative defines computation as statements that change a program state

Slide 31

Slide 31 text

Imperative defines computation as action that change a program state

Slide 32

Slide 32 text

Imperative

Slide 33

Slide 33 text

Imperative

Slide 34

Slide 34 text

Imperative

Slide 35

Slide 35 text

Imperative

Slide 36

Slide 36 text

Imperative Share Memory

Slide 37

Slide 37 text

Imperative Share Memory Side effects

Slide 38

Slide 38 text

Imperative Share Memory Nondeterministic Side effects

Slide 39

Slide 39 text

Functional

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 treats computation as the evaluation of mathematical functions and avoids state and mutable data

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

Functional

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Determinism

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Functional - Bound/Unbound Variable

Slide 57

Slide 57 text

Functional - Bound/Unbound Variable

Slide 58

Slide 58 text

Functional - Bound/Unbound Variable

Slide 59

Slide 59 text

Functional - Bound/Unbound Variable

Slide 60

Slide 60 text

Functional - Bound/Unbound Variable

Slide 61

Slide 61 text

Determinism 24

Slide 62

Slide 62 text

Determinism 24

Slide 63

Slide 63 text

Determinism

Slide 64

Slide 64 text

Concurrency

Slide 65

Slide 65 text

Imperative

Slide 66

Slide 66 text

Threads and Locks

Slide 67

Slide 67 text

Threads and Locks shared memory

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

Threads and Locks dataflow variable

Slide 74

Slide 74 text

Threads and Locks dataflow variable functional

Slide 75

Slide 75 text

Thread and Locks

Slide 76

Slide 76 text

Thread and Locks

Slide 77

Slide 77 text

Thread and Locks

Slide 78

Slide 78 text

Thread and Locks Unbound

Slide 79

Slide 79 text

Thread and Locks Unbound

Slide 80

Slide 80 text

Thread and Locks Unbound Bound

Slide 81

Slide 81 text

Determinism

Slide 82

Slide 82 text

Java = Imperative

Slide 83

Slide 83 text

Thread and Locks

Slide 84

Slide 84 text

Thread and Locks

Slide 85

Slide 85 text

Thread and Locks

Slide 86

Slide 86 text

Thread and Locks

Slide 87

Slide 87 text

Thread and Locks

Slide 88

Slide 88 text

Thread and Locks

Slide 89

Slide 89 text

Thread and Locks

Slide 90

Slide 90 text

Thread and Locks

Slide 91

Slide 91 text

Thread and Locks The meaning of life is: ?

Slide 92

Slide 92 text

Thread and Locks The meaning of life is: 0

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

Thread and Locks The meaning of life is: 0

Slide 95

Slide 95 text

Thread and Locks Mutable State

Slide 96

Slide 96 text

Thread and Locks Race condition

Slide 97

Slide 97 text

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

Slide 98

Slide 98 text

Thread and Locks Optimization

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

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

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

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

Slide 104

Slide 104 text

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

Slide 105

Slide 105 text

Thread and Locks synchronize

Slide 106

Slide 106 text

Trade-off + Common + Lock control

Slide 107

Slide 107 text

Trade-off - Lock Control - Mutual Exclusion, dead lock… - Excessive Contention

Slide 108

Slide 108 text

Functional

Slide 109

Slide 109 text

Actor

Slide 110

Slide 110 text

Actor message-passing

Slide 111

Slide 111 text

Actor

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

Actor

Slide 114

Slide 114 text

Actor

Slide 115

Slide 115 text

Goroutines and Channels message-passing

Slide 116

Slide 116 text

Goroutines and Channels

Slide 117

Slide 117 text

Microthreads with a internal scheduler 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

Goroutines and Channels

Slide 126

Slide 126 text

Trade-off + No Sinc + Distribution

Slide 127

Slide 127 text

Trade-off + Incommon + Complex

Slide 128

Slide 128 text

References

Slide 129

Slide 129 text

References

Slide 130

Slide 130 text

References

Slide 131

Slide 131 text

The design and characteristics of a programming language are defined by the creator, based in his problems, at the creation moment @Scalone

Slide 132

Slide 132 text

THANK YOU! @Scalone