Save 37% off PRO during our Black Friday Sale! »

Concurrency in the imperative and functional world

Concurrency in the imperative and functional world

Why functional programing languages tend to be more effective than imperative programing languages when you talk about concurrency

E822acb0564c5632aae69fef35f85b3d?s=128

Scalone

June 09, 2017
Tweet

Transcript

  1. @Scalone Concurrency in the imperative and functional world

  2. Thiago Scalone thiago@scalone.com.br @scalone

  3. None
  4. None
  5. None
  6. … nothing new … DISCLAIMER

  7. If you don't understand concurrency… it isn’t problem if doesn't

    make part of your day. DISCLAIMER
  8. Context 1

  9. None
  10. None
  11. None
  12. None
  13. None
  14. Context 2

  15. None
  16. Concurrency

  17. Concurrency Parallelism

  18. “Dealing a lot of things at once Rob Pike about

    Concurrency
  19. “Doing a lot of things at once Rob Pike about

    Parallelism
  20. @Scalone

  21. @Scalone

  22. @Scalone

  23. @Scalone

  24. @Scalone

  25. @Scalone

  26. @Scalone

  27. Context 3

  28. Imperative

  29. Imperative

  30. Imperative defines computation as statements that change a program state

  31. Imperative defines computation as action that change a program state

  32. Imperative

  33. Imperative

  34. Imperative

  35. Imperative

  36. Imperative Share Memory

  37. Imperative Share Memory Side effects

  38. Imperative Share Memory Nondeterministic Side effects

  39. Functional

  40. Functional treats computation as the evaluation of mathematical functions and

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

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

    avoids state and mutable data
  43. Functional

  44. Functional

  45. Functional

  46. Functional

  47. Functional

  48. Functional

  49. None
  50. Determinism

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

  52. Determinism - Same In => Same out no disk I/O

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

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

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

    no side effects no random() always the same result f(x) -> y
  56. Functional - Bound/Unbound Variable

  57. Functional - Bound/Unbound Variable

  58. Functional - Bound/Unbound Variable

  59. Functional - Bound/Unbound Variable

  60. Functional - Bound/Unbound Variable

  61. Determinism 24

  62. Determinism 24

  63. Determinism

  64. Concurrency

  65. Imperative

  66. Threads and Locks

  67. Threads and Locks shared memory

  68. Thread and Locks

  69. Thread and Locks

  70. Thread and Locks

  71. Thread and Locks

  72. Thread and Locks

  73. Threads and Locks dataflow variable

  74. Threads and Locks dataflow variable functional

  75. Thread and Locks

  76. Thread and Locks

  77. Thread and Locks

  78. Thread and Locks Unbound

  79. Thread and Locks Unbound

  80. Thread and Locks Unbound Bound

  81. Determinism

  82. Java = Imperative

  83. Thread and Locks

  84. Thread and Locks

  85. Thread and Locks

  86. Thread and Locks

  87. Thread and Locks

  88. Thread and Locks

  89. Thread and Locks

  90. Thread and Locks

  91. Thread and Locks The meaning of life is: ?

  92. Thread and Locks The meaning of life is: 0

  93. None
  94. Thread and Locks The meaning of life is: 0

  95. Thread and Locks Mutable State

  96. Thread and Locks Race condition

  97. Race Condition the output is dependent on the sequence or

    timing of other uncontrollable events
  98. Thread and Locks Optimization

  99. Optimization the compiler is allowed to statically optimize your code

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

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

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

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

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

    performance by reordering things
  105. Thread and Locks synchronize

  106. Trade-off + Common + Lock control

  107. Trade-off - Lock Control - Mutual Exclusion, dead lock… -

    Excessive Contention
  108. Functional

  109. Actor

  110. Actor message-passing

  111. Actor

  112. Actor An object which encapsulates state and communicates with other

    actors by exchaging messages
  113. Actor

  114. Actor

  115. Goroutines and Channels message-passing

  116. Goroutines and Channels

  117. Microthreads with a internal scheduler Goroutines and Channels

  118. Goroutines and Channels

  119. Goroutines and Channels

  120. Goroutines and Channels

  121. Goroutines and Channels

  122. Goroutines and Channels

  123. Goroutines and Channels

  124. Goroutines and Channels

  125. Goroutines and Channels

  126. Trade-off + No Sinc + Distribution

  127. Trade-off + Incommon + Complex

  128. References

  129. References

  130. References

  131. The design and characteristics of a programming language are defined

    by the creator, based in his problems, at the creation moment @Scalone
  132. THANK YOU! @Scalone