Download - Concurrent programming1
![Page 1: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/1.jpg)
Highly Concurrent ProgrammingNick Brandaleone Lecture 1
![Page 2: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/2.jpg)
![Page 3: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/3.jpg)
The End of Moore’s Law
![Page 4: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/4.jpg)
The End of Moore’s Law
Why we don’t have 10 GHz chips today
Chips are too big
Signals can no longer reach the whole chip in a clock cycle
Problems with heat dissipation
![Page 5: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/5.jpg)
The Multicore Era
Manufactures have turned towards multi-core processors in order to increase speed
They are capable of doing multiple calculations in parallel
CPU speeds are likely to stay relatively flat
![Page 6: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/6.jpg)
![Page 7: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/7.jpg)
The Concurrency RevolutionIntel HyperThreading - hardware supported
Future computer architectures will have greater number of cores, from the desktop (12 typical for workstation) to the smartphone (2 in iPhone)
You will need to develop well-written concurrent applications to gain from this hardware development
![Page 8: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/8.jpg)
Vocabulary
Parallelism
Programming as the simultaneous execution of (possibly related) computations
Concurrency
Programming as the composition of independently executing processes
![Page 9: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/9.jpg)
![Page 10: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/10.jpg)
![Page 11: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/11.jpg)
![Page 12: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/12.jpg)
Shared State ConcurrencyThreads concurrently execute code
Contains resources that must be shared
Synchronization is required via locks
Data consistency
Visibility
Correct ordering
![Page 13: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/13.jpg)
![Page 14: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/14.jpg)
Why locking is evil“non-trivial multi-threaded programs are incomprehensible to human …” - Edward A. Lee, The Problem with Threads
“humans are quickly overwhelmed by concurrency and find it much more difficult to reason about concurrent than sequential code” - Sutter and Larus
“I have a firm belief that locking primitives are evil”
![Page 15: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/15.jpg)
![Page 16: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/16.jpg)
Message Passing
Carl Hewitt, Richard Steiger and Peter Bishop released a paper in 1973 introducing the Actor Model concept
C.A.R. Hoare: Communicating Sequential Processes (CSP). Introduced in 1978.
Very similar concepts. We shall refer to them both as “message passing” (aka process calculus)
![Page 17: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/17.jpg)
![Page 18: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/18.jpg)
![Page 19: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/19.jpg)
![Page 20: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/20.jpg)
Alternative ModelsLanguage Method
Erlang Actors
Go Concurrent Sequential Processing
Clojure Software Transactional Memory
Icon Coexpressions
![Page 21: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/21.jpg)
Key Concepts
Actors (or go routines) instead of objects
No shared state between actors
Asynchronous message-passing
Share memory by communicating
![Page 22: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/22.jpg)
Amdahl’s Law
![Page 23: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/23.jpg)
Goals for this course:Learn Concurrent Programming using CSP/Actor model Become familiar with concurrent programming idioms
All assignments can be fulfilled using Language of choice •Elixir (Erlang) •Go (the new “C”) •Scala (Java) •Haskell (purely functional)
Grade •Weekly HW •Mid-term quiz •Final Project
![Page 24: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/24.jpg)
The Languages
![Page 25: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/25.jpg)
ErlangA functional, dynamically typed language
Invented at Ericsson in 1986
Designed for concurrency, scalability and reliability
![Page 26: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/26.jpg)
Erlang in the real worldEricsson ATM switch (301 model)
99.9999999 percent uptime
Facebook chat
100s of millions concurrent users
RabbitMQ
High performance AMQP
Apache CouchDB
distributed, fault-tolerant document DB
![Page 27: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/27.jpg)
![Page 28: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/28.jpg)
![Page 29: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/29.jpg)
Syntactic Sugar for Erlang
![Page 30: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/30.jpg)
Elixir example
![Page 31: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/31.jpg)
Go LanguageDeveloped by Rob Pike, formerly of Bell Labs
Statically compiled and typed language, loosely based upon C syntax
Supports Garbage Collection, and Concurrency
Used internally at Google
Strong community support and documentation
![Page 32: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/32.jpg)
Go example
![Page 33: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/33.jpg)
Scala
The new “Java”. Runs on Java VM
Object oriented and functional design
Very flexible
Can use Java libraries
Syntax can be tough due to mix of OO and F
![Page 34: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/34.jpg)
Scala example
![Page 35: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/35.jpg)
Haskell
Purely functional programming language
Built-in support for concurrency and parallelism
Typically used more in research community than commercially
Powerful but confusing syntax
![Page 36: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/36.jpg)
Haskell example
![Page 37: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/37.jpg)
FUNCTIONAL VS IMPERATIVE OR OOPROGRAMMING STYLES
![Page 38: Concurrent programming1](https://reader035.vdocument.in/reader035/viewer/2022062319/553a40544a7959c1688b4a56/html5/thumbnails/38.jpg)
Homework
Research language that you would like to use
Watch http://blog.golang.org/concurrency-is-not-parallelism video by Rob Pike
Work on Assignment #1 for next week